Code example:
private function onCreationComplete():void {
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(flash.events.IOErrorEvent.IO_ERROR, onIoError);
fileRef.addEventListener(flash.events.DataEvent.UPLOAD_COMPLETE_DATA, responseHandler);
}
private function selectHandler(event:Event):void {
filename.text = fileRef.name;
}
private function selectFile():void {
try
{
var success:Boolean = fileRef.browse();
}
catch (error:Error)
{
trace("Unable to browse for files.");
}
}
private function onIoError(event:flash.events.IOErrorEvent):void{
Alert.show(rm.getString('ui_res', 'file_uppload_fail'), rm.getString('ui_res', 'connection_error'));
ModelLocator.getInstance().confManagerModel.isPending = false;
}
private function onUploadDataComplete(event:flash.events.DataEvent):void {
trace("onUploadDataComplete");
}
private function responseHandler( event:DataEvent ) :void {
var data:Object = JSON.decode(event.data as String);
// do anything with data
}
private function uploadFile():void
{
if(!submit.enabled){
return;
}
var request:URLRequest = new URLRequest("test")
try
{
fileRef.upload(request);
ModelLocator.getInstance().confManagerModel.isPending = true;
}
catch (error:Error)
{
Alert.show(rm.getString('ui_res', 'file_uppload_fail'), rm.getString('ui_res', 'error_on_server'));
}
}
private function completeHandler(event:Event):void
{
}