You can load an external image to your flash application very easily via actionscript 3.0. This is very common requirements when making a dynamic image gallery using actionscript/flash. As images may be changed, they need to be loaded somehow dynamically. Here is the place actionscript helps.
First, what you will need a loader object that is actually being used for many other purposes also. You will also need to add an event listener which will be triggered whenever the images loading completed.
var __loader = new Loader();
__loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onThumbnailLoaded);
To request, you will also need an another class object named 'UrlRequest' object. As soon as its done, you can request to load the image:
__request = new URLRequest(urlpath);
__loader.load(__request);
When the loading is completed, you can use the loader object as your received data
and use this anywhere you want. If you are currently in a movieclip now. You can add this as child movieclip like as follows:
function onThumbnailLoaded(evnt:Event){
addChild(__loader);
}
Now run your application and notice the loaded image on the swf movie.
Points to remember:
* URL must need to be valid. otherwise no image will be loaded. If there is possibility to be the URL wrong, then please use error event handler to track that. if you want the image loaded from clients pc. There will be need to add some more code with FileReference class.
* if you want to scale/provide a specific position to your image. use loader objects property to do that.
* You can also track the loading info, how much loaded. This is required when you are using progress bar to show the progress stat of image loading.
Subscribe to:
Post Comments (Atom)










1 comments:
Nice script! The script you have posted is quiet useful & interesting.
Post a Comment