Downloading a simple file with AS3
Filed under Lab Work, Programming | Tags:Actionscript 3,FileReference,Flash
FIleRefrence class: This is the guy you need to use if you want to enable a file for download to a client (your local computer). i could have hit my head against the wall for days trying to understand why i was getting the window that appeared to want to download a file, but simply would not. The fact is, the FileRefrence object you will use can not be a local object to the function that is calling the download…say that again.
Ok, this post solved my problems.
//early in the class private var fu:FileReference; //CUSTOM CONTEXT MENU--------------------------------------------------------------------- private function addCustomMenu(cm:ContextMenu) { var new_cm:ContextMenuItem= new ContextMenuItem("All content ©me") var res:ContextMenuItem=new ContextMenuItem("download resume") res.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,getile) cm.customItems.push(new_cm) cm.customItems.push(res) } private function getfile(cme:ContextMenuEvent):void { fu=new FileReference() var resumeRequest:URLRequest=new URLRequest() resumeRequest.url=primary.gateway+"assets/CV.doc"; fu.download(resumeRequest,"filename.doc") }