PDA

View Full Version : Setting the dimension of a loader



eudora
June 2nd, 2007, 02:25 PM
Say I have a function loadAsset which creates a loader to load the url for the graphics. But I want to resize it. Doing it immediately after calling loader.load(url) will not work, it will instead result in the loader to disappear as its width and height will be 0.

Example pseudo code (not functional just a rough idea...)


function loadAsset(url:String){
var loader = new Loader();
loader.load(url);
loader.width = 100;
loader.height = 100;
addChild(loader);
}

If I use a event to dispatch when the graphics are loaded finish and then set the dimension, this will work.
Example, again pseudo code


function loadAsset(url:String){
var loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadComplete);
loader.load(url);
addChild(loader);
function loadComplete(event){
loader.width = 100;
loader.height = 100;
}
}
Now my question is... say I have an array of URL to load.. how should I structure the code so that the resizing of each individual URL is correct? Because when I tried to use example 2, in a loop, the loaded asset does not seem to be resized correctly...

eudora
June 2nd, 2007, 11:33 PM
Ah okie, I got it to work using
event.target.content.width
event.target.content.height
In the event function. :)