Ciao ragazzi sto realizzando un uploader in as3 con barra progressiva.
Questo uploader invia alcuni dati tramite post e uppa il file, io vorrei che mi desse anche un response del mio file uploader.php.
è possibile? come si fa?
codice:import flash.events.MouseEvent; import flash.net.FileReference; import flash.net.FileFilter; import flash.utils.ByteArray; import flash.events.MouseEvent; import flash.events.Event; import flash.events.IOErrorEvent; import flash.display.MovieClip; import fl.controls.ProgressBarMode; var mFileReference:FileReference; // Setup button to handle browsing browseButton.buttonMode=true; browseButton.mouseChildren=false; browseButton.addEventListener(MouseEvent.CLICK, onBrowseButtonClicked); // Hide progress bar progressBar.visible=false; // This function is called when the BROWSE button is clicked. function onBrowseButtonClicked(event:MouseEvent):void { trace("onBrowse"); mFileReference=new FileReference(); mFileReference.addEventListener(Event.SELECT, onFileSelected); var swfTypeFilter:FileFilter = new FileFilter("FLV Files","*.flv"); var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*"); mFileReference.browse([swfTypeFilter,allTypeFilter]); } // This function is called after user selected a file in the file browser dialog. function onFileSelected(event:Event):void { trace("onFileSelected"); if (mFileReference.size < 512000*1024) { // This callback will be called when the file is uploaded and ready to use mFileReference.addEventListener(Event.COMPLETE, onFileLoaded); // This callback will be called if there's error during uploading mFileReference.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError); // Optional callback to track progress of uploading mFileReference.addEventListener(ProgressEvent.PROGRESS, onProgress); // Tells the FileReference to load the file mFileReference.load(); // Show progress bar progressBar.visible=true; progressBar.mode=ProgressBarMode.MANUAL; progressBar.minimum=0; progressBar.maximum=100; } else { stato.text="Invalid max file size"; } } // This function is called to notify us of the uploading progress function onProgress(event:ProgressEvent):void { var percentLoaded:Number=event.bytesLoaded/event.bytesTotal*100; stato.text=("loaded: "+percentLoaded+"%"); progressBar.setProgress(percentLoaded, 100); } // This function is called after the file has been uploaded. function onFileLoaded(event:Event):void { var params:URLVariables = new URLVariables(); params.percorso = "video/"; mFileReference.removeEventListener(Event.COMPLETE, onFileLoaded); mFileReference.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError); mFileReference.removeEventListener(ProgressEvent.PROGRESS, onProgress); var filename:String=mFileReference.name; var urlRequest:URLRequest = new URLRequest("uploader.php"); urlRequest.method = URLRequestMethod.POST; urlRequest.data = params; browseButton.visible=false; // Optional callback to track progress of uploading mFileReference.addEventListener(ProgressEvent.PROGRESS, onProgress); mFileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadComplete); mFileReference.upload(urlRequest); } function onFileLoadError(event:Event):void { // Hide progress bar progressBar.visible=false; mFileReference.removeEventListener(Event.COMPLETE, onFileLoaded); mFileReference.removeEventListener(IOErrorEvent.IO_ERROR, onFileLoadError); mFileReference.removeEventListener(ProgressEvent.PROGRESS, onProgress); browseButton.visible=true; progressBar.visible=false; stato.text=("File load error"); } function onUploadComplete(event:Event):void { // Optional callback to track progress of uploading mFileReference.removeEventListener(ProgressEvent.PROGRESS, onProgress); FileReference.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadComplete); browseButton.visible=true; progressBar.visible=false; }

Rispondi quotando