aF.
aF.

Reputation: 66727

How to load a image from directory using flash?

I want to click on a button and then choose a image to load (browsing directories) and use it as background.

Is that possible using flash and actionscript 3?

Upvotes: 1

Views: 5593

Answers (2)

Bartek
Bartek

Reputation: 1996

Use Loader class to do this:

function LoadImage(imageURL:String) {
    var imageLoader:Loader = new Loader();
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, ImageLoaded); // event listener which is fired when loading is complete
    imageLoader.load(new URLRequest(imageURL));
}

function ImageLoaded(e:Event) {
    e.target.loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, ImageLoaded);
    this.addChild(e.target.loader.content); // loaded content is stored in e.target.loader.content variable
}

But, if you want to load image from local directory you can use FileReference class to do that, read the documentation for more details.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html

Upvotes: 4

a.b
a.b

Reputation: 9574

Yes it is, use Loader class... read here for how to use it.

Upvotes: 0

Related Questions