simple but pretty darn stuck - wait the images load

I think it's pretty simple, but I'm not able to do this. situation is something like this:

function name123 (): void //i m already in service.
{
....
var a: Loader = new Loader(); define a charger
var b: new URLRequest = new URLRequest (image path); give the path
a.Load (b);
a.contentLoaderInfo.addEventListener (Event.COMPLET, Evenementcomplete);
now the code after this line, I want that they don't run until the above has finished loading. because if I type the codes below, it will not work.
a.Width = 100;
a.Height = 100;
}

function eventComplete(e:Event):void
{
codes
}

I know that if I give you set width and height in function Evenementcomplete, I could do, but the situation is different and I have to set the sizes based on name123 only. kindly help out me... its been two days now...

I think that this flow is quite inefficient and, above all, expensive in terms of consumption of memory. Also, this approach is quite rigid.

Here's some code that performs a virtually unlimited number of images loading. The only thing to do is to fill imageURLs with proper URL. It may not match all needs, but because the references to the loaded images are stored in one place - you can always find them during execution:


var imagURLs:Array = ["img0.jpg", "img1.jpg", "img2.jpg", "img3.jpg", "img4.jpg"];// array of objectsvar images:Array = [];var loadCounter:int = 0;loadImages();

function loadImages():void {     var loader:Loader;     for (var i:int = 0; i < images.length; i++) {          loader = new Loader();          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);          loader.load(new URLRequest(images[i]));          images.push({loader: loader, index: i});     }}

function onLoadComplete(e:Event):void {     LoaderInfo(e.target).removeEventListener(Event.COMPLETE, onLoadComplete);     loadCounter++;     if (loadeCounter == imgURLs.length) setSizes();}

function setSizes():void{     var image:Bitmap;     for each(var obj:Object in images) {          image = obj.loader.content;          image.width = 200;          image.height = 100;          obj.image = image;     }}

Tags: Adobe Animate

Similar Questions

Maybe you are looking for