Pages

Showing posts with label How upload your Image file in as3. Show all posts
Showing posts with label How upload your Image file in as3. Show all posts

Sunday, April 29, 2012

How to upload local disk IMAGE in FLASH AS3




Here we have use to FileRefrence Class.

What is mean FileRefrence?
       
         A FileReference object represents a data file on a client or server machine. The methods of the FileReference class let your application load and save data files locally, and transfer file data to and from remote servers.


Example:-

package 
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.events.Event;

/**
* ...
* @author KUMARESH NRV
*/
public class Upload extends Sprite  
{
 
private var fileRef:FileReference;
private var imageTypes:FileFilter;

/** constructor **/
public function Upload():void
{
init();
}

/**
* @details init function
*/
private function init():void
{
fileRef = new FileReference();
fileRef.addEventListener(Event.SELECT, onSelectFile);
fileRef.addEventListener(Event.COMPLETE, onLoadComplete);
imageTypes = new FileFilter("Images (*.jpg, *.png)", "*.jpg;*.png");
upload_mc.addEventListener(MouseEvent.CLICK, onShowUploadPage);
}
 
/**
* @details file reference page display
* @param event
*/
private function onShowUploadPage(event:MouseEvent):void
{
fileRef.browse([imageTypes]);
}
 
/**
* @details on select image file
* @param event
*/
private function onSelectFile(event:Event):void
{
fileRef.load();
}
 
/**
* @details on image load complete
* @param event
*/
private function onLoadComplete(event:Event):void
{
imageStage_mc.loadBytes(fileRef.data);
}
}

}



here FileFilter using for filter to image files (image,text,doc,etc.)
and then imageStage_mc is UILoader Component.


try it Friends.

...CHeeRS...