ActionScript 3.0: load an image programmatically

actionscript-3adobe

I'm developing an Blackberry Playbock app with ActionScript 3.0. I'm very very new with this.

I have the following project structure (I'm using Adobe Flash Builder "Burrito"):

project
|
src
|
assets
|
images

On image folder I have several PNGs images that I want to load programmatically.

How can I do that?

And

What GUI component I must use to show an image?

Best Answer

This example loads one image and uses buttons to change it:

// create a Loader object to hold things that you will load
var myLoader:Loader = new Loader();

// position the Loader
myLoader.x = 250;
myLoader.y = 0;

// put something into the Loader 
myLoader.load(new URLRequest("tree.jpg"));

// make the Loader visible
addChild(myLoader);

// button listeners
top_btn.addEventListener(MouseEvent.CLICK, loadPhoto);
last_btn.addEventListener(MouseEvent.CLICK, unloadAny);

// button functions
function loadPhoto(e:MouseEvent):void {
    myLoader.load(new URLRequest("sailboat.jpg"));
    addChild(myLoader);
}
// this function empties the Loader object 
function unloadAny(e:MouseEvent):void {
    removeChild(myLoader);
}
Related Topic