Jump to content
Search Community

Add vars to ImageLoader

Alex_Shim test
Moderator Tag

Recommended Posts

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.
×
×
  • Create New...