Amass

Loading(and then scaling) an image using AS 2.0

March 3rd, 2008 Luke

Have you ever struggled with first loading in, and then scaling an image using ActionScript 2.0?

Loading and scaling images using ActionScript used to be the one thing in Flash that I struggled most with - I just couldn’t seem to find a nice way to get it done. But as it turns out, it’s already been done for me - the MovieClipLoader class exists for exactly the kind of voodoo I need:

var handler:Object = new Object(); handler.onLoadInit = function(mc:MovieClip) { if(mc._width != 200) { mc._width = 200; } if(mc._height != 200) { mc._height = 200; } } var target:MovieClip = createEmptyMovieClip("target",getNextHighestDepth()); var loader:MovieClipLoader = new MovieClipLoader(); loader.addListener(handler); loader.loadClip("my/image/path.jpg",target);

That code, when executed, will load the image at path my/image/path.jpg into the new movie clip we created, and then scale it to 200×200.