/ Published in: MXML
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="OnCreationComplete(event)"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; public var fileRef:FileReference = new FileReference(); protected function OnCreationComplete(event:FlexEvent): void { fileRef.addEventListener(Event.SELECT, OnFileSeletected); fileRef.addEventListener(Event.COMPLETE, OnUploadComplete); } public function OnFileSeletected(event:Event) : void { var request:URLRequest = new URLRequest("http://name-of-your-server/FlexChannel/VideoUpload"); request.method = URLRequestMethod.POST; try{ fileRef.upload(request); } catch(error:Error){ trace(error.message); } } public function OnUploadComplete(event:Event) : void{ trace("complete"); } public function OnOpenClicked(event:MouseEvent) : void{ fileRef.browse([new FileFilter("Videos", "*.mov;*.avi;*.mp4;*.mpeg")]); } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:Button label="Upload" click="OnOpenClicked(event)"/> </s:Application>