Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
fl.Ash

Loading multiple images

Recommended Posts

Hello guys, 

 

This is my first time using LoaderMax to load assets as I usually use the Starling asset manager however I am working on a standard flash application now and have had good experiences with TweenMax and TweenLite so thank you for providing these awesome tools!

 

I am trying to load multiple images (pngs + jpegs) using the ImageLoader. It is working fine but I am looking for a way to be able to not add the images to the screen as soon as they are loaded and make them accessible to child sprites that I can't specify in the container parameter (These sprites are different screens which are created and destroyed as needed and do not exist at the time of loading). 

 

So basically, what is the best way to make these images accessible throught my application and not just in the class they are loaded in (this class is still a parent of all the sprites I will need to use these images in).

 

Regards,

 

Ash. 

Link to post
Share on other sites

Just realised that I can just say LoaderMax.getContent from within any child of the parent sprite that my assets are loaded inside. 

 

Thanks anyway :)

Link to post
Share on other sites

Hi and welcome to the GreenSock forums,

 

Its not fair if you find the answers while I'm still sleeping;)

 

Thanks for letting us know you solved it, using LoaderMax.getContent() is the way to go!

Link to post
Share on other sites

Thanks for the help Carl,

 

Although I did overcome this issue, I've come up against an issue with LoaderMax.getContent().

 

If I want two variables to use the same image I have loaded, how do I change the variable without affected the actual loaded content e.g:

 

<as3>

 

buttonUpImage = LoaderMax.getContent("button");

buttonUpImage.centerRegistration = true;

buttonUpImage.width = 200;

buttonUpImage.scaleY = buttonUpImage.scaleX;

 

buttonDownImage = LoaderMax.getContent("button");

buttonDownImage.centerRegistration = true;

buttonDownImage.width = 150;

buttonDownImage.scaleY = buttonDownImage.scaleX;

 

button = new SimpleButton(buttonUpImage, buttonUpImage, buttonDownImage, buttonUpImage);

this.addChild(button);

 

</as3>

 

Using the above code causes sets the width of both images to 150.

Link to post
Share on other sites

Also tried:

 

<as3>

 

buttonContent = LoaderMax.getContent("button");
 
buttonUpImage = buttonContent.rawContent;
buttonUpImage.width = 200;
buttonUpImage.scaleY = buttonUpImage.scaleX;
buttonUpImage.x = buttonUpImage.width * 0.5;
buttonUpImage.y = buttonUpImage.height * 0.5;
 
buttonDownImage = buttonContent.rawContent;
buttonDownImage.width = 150;
buttonDownImage.scaleY = buttonDownImage.scaleX;
buttonDownImage.x = buttonUpImage.width * 0.5;
buttonDownImage.y = buttonUpImage.height * 0.5;
 
</as3>
 
This still changes both.
Link to post
Share on other sites

Yeah you have 2 references to the same asset. You need to load a separate image for each state.

ImageLoader is very smart though, and if you create 2 ImageLoaders that point to the same image url, it will simply copy the bitmap data from the first ImageLoader to all subsequent ImageLoaders.

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

var lm:LoaderMax = new LoaderMax({onChildComplete:showCrabs});
var crab1:ImageLoader = new ImageLoader("images/crab.png");


//this next loader is never loaded, the crab pixels are copied from crab1
var crab2:ImageLoader = new ImageLoader("images/crab.png");




lm.append(crab1)
lm.append(crab2)

lm.load();


function showCrabs(e:LoaderEvent):void {
addChild(crab1.content);
addChild(crab2.content);
crab2.content.scaleX = crab2.content.scaleY = 0.5;
}

CS5 example attached

 

If you don't want to create a separate ImageLoader, you can copy the bitmap data yourself http://www.flashandmath.com/howtos/bddraw/

 

loadImageTwice_CS5.zip

Link to post
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.

×