Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Alex_Shim

Add vars to ImageLoader

Recommended Posts

Is there some simple way to add some vars to ImageLoader? I mean, like this:

thumbLoader.append(new ImageLoader(thumbnail_images[i], {name:"photo"+i, container:this, lalala_var:i}));
Link to comment
Share on other sites

G'day mate,
 
You can add and access custom user properties using the following method:

public function Main() 
{
    var il:ImageLoader = new ImageLoader("myImage.png",new ImageLoaderVars()
    .name("myImage")
    .container(stage)
    .onComplete(loadedImage)
    .prop("lalala", "myValue")); //Use the prop method of imageloader vars to add a property. name , value
			
    il.load()
			
}
		
private function loadedImage(e:LoaderEvent):void 
{
    var vars:Object = ImageLoader(e.currentTarget).vars;
    //access your custom variable name now
    trace(vars.lalala);
}

Or if you prefer a more inline approach instead of the ImageLoaderVars:

public function Main() 
{
	//Or if you prefer inline
	var il:ImageLoader = new ImageLoader("myImage.png", { name:"myImage", container:stage, onComplete:loadedImage, lalala: "myValue2"} );	
	il.load()
}

private function loadedImage(e:LoaderEvent):void 
{
	var vars:Object = ImageLoader(e.currentTarget).vars;
	//access your custom variable name now
	trace(vars.lalala); //traces myValue2
}
  • Like 2
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.
×