homer gaines posted quite nice comparison article on importing images within ActionScript 2 and 3 versions:
If you are going to develop flash based content using AS3, you should know it takes a bit more work to do simple things. For example, say for inistance you want to load an image into a movie clip called “imgHold_mc” using ActionScript 2, you could use the following code:
function loadImage() {
imgHold_mc.loadMovie(imgUrl);
}
loadImage();
-or-
var url:String = “imgUrl”;
function loadImage(link:String){
imgHold.loadMovie(link);
}
loadImage(url);If you wanted to do the same thing but using ActionScript 3, you would need to use the code bellow:
var imageLoader:Loader;
function loadImage(url:String):void {
imageLoader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
loadImage(imgUrl);
function imageLoaded(e:Event):void {
imgHold_mc.addChild(imageLoader);
}
2 comments:
var imageLoader:Loader = new Loader();
imageLoader.load(new URLRequest(url));
imgHold_mc.addChild(imageLoader);
3 lines of code... Can't get much simpler... AS3 is much more powerful and has a LOT more benefits than AS2!!
But hey... it's your call...
I think you don't need the event listener in AS3 (just like you left out the event listener in AS2). I'm pretty sure you can call addChild without waiting for the load to finish.
Post a Comment