actionscript 3.0 Loading image-swf from local file system

This is an example how to load a image file from local hdd to swf file running in a browser.


//file referance
var refer:FileReference=new FileReference();
//file filter
var imagesFilter:FileFilter=new FileFilter("Images","*.jpg;*.gif;*.png");
//loader
var loader:Loader=new Loader();
//event listener for file selection event
refer.addEventListener(Event.SELECT, selectHandler);
// event listener for load complete
refer.addEventListener(Event.COMPLETE, done);

function selectHandler(e:Event):void {
// load the file after file selection
refer.load();

}
function done(e:Event) {
//load the byte array from the loaded data
loader.loadBytes(refer.data);
//add the loader to stage
addChild(loader);
//loadevent handler for loader
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageDone);

}
//button clickevent listener
btn1.addEventListener(MouseEvent.CLICK,loadImage)
function loadImage(e:Event){
//show the browser window after click the button
refer.browse([imagesFilter]);
}

function onImageDone(e:Event){
//resize the image after it add to stage
loader.width=200;
loader.height=200;
}

sample source file will be uploaded soon.

0 comments:


PHP developer Cochin |PHP developer Kerala | PHP developer India | Flash developer/programmer Cochin | Flash developer/programmer Kerala | Flash developer/programmer India | web programmer kerala |web programmer Cochin |web programmer India |web developer kerala |Web developer Cochin | Kerala PHP | PHP freelancer| flash actionscript freelancer