Jump to content
Search Community

addChild(ImageLoader)

deshu test
Moderator Tag

Recommended Posts

Hi Deshu,

 

There are a couple of ways to add your loaded image from the image Loader to your displaylist. The easiest way is just to use the container var like so:

 

var iLoad:ImageLoader = new ImageLoader("myFile.jpg", new ImageLoaderVars()
.container(yourContainer)
)
iLoad.load();

 

After the image has finished loading it will automatically add the ContentDisplay image to whatever container you specify.

The other way is to listen to the COMPLETE method of the imageloader and then use addChild from there.

 

public function test() {

var iLoad:ImageLoader = new ImageLoader("myFile.jpg", new ImageLoaderVars()
.name("myFile")
)
iLoad.addEventListener(LoaderEvent.COMPLETE, imgLoaded)

iLoad.load();
}

private function imgLoaded(e:LoaderEvent):void 
{
addChild( LoaderMax.getContent("myFile") );
}

 

Note going this way, you should give a name var to the imageloader so you can easily access it later.

Link to comment
Share on other sites

  • 3 weeks later...

Hello...

first of all, Jack THANK YOU!!!

I didn't start new topic because my question is, I believe, similar to Deshu's.

 

Is there any way to use ImageLoaderVars .container() and .onComplete() together, to add images to container after onComplete is dispatched?

In other words, I need to load set of images (through XML), and I would like to use ImageLoaderVar property .onComplete, and when all images are loaded, I want to put them to display.

 

Thanks.

Link to comment
Share on other sites

Sure. Do you need to associate a different container with each loader? If not, you could do this:

 

var loader:ImageLoader = new ImageLoader("1.jpg", {onComplete:completeHandler});
loader.load();
function completeHandler(event:LoaderEvent):void {
   myContainer.addChild(event.target.content);
}

 

Or if you've got them in a LoaderMax queue, you could all at once when the whole queue completes like:

 

var queue:LoaderMax = new LoaderMax({onComplete:completeHandler});
queue.append( new ImageLoader("1.jpg") );
...append more loaders...
queue.load();

function completeHandler(event:LoaderEvent):void {
   var images:Array = queue.content; //a LoaderMax's content is an array of all its child loaders' content
   for (var i:int = 0; i         myContainer.addChild(images[i]);
   }
}

 

Or if you want to add each image as it completes in the queue, you could do this:

 

var queue:LoaderMax = new LoaderMax({onChildComplete:childCompleteHandler});
queue.append( new ImageLoader("1.jpg") );
...append more loaders...
queue.load();

function childCompleteHandler(event:LoaderEvent):void {
   myContainer.addChild(event.target.content);
}

 

Lots of options :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...