Skip to main content
Known Participant
November 12, 2010
Answered

cant display log images

  • November 12, 2010
  • 3 replies
  • 903 views

I am loading a series of images that animate a sinking log. The log sinks down in water and then rises back up  so I display 3 images to sink and the same images in reverse so it rises again and repeated continually.

What I get is the images being displayed in some weird order and not in the order as in urls16?

I cant display these images in the order given below?

I dont get any error.

private var urls16:Array = ["images/logW1.png", "images/logW2.png", "images/logW3.png", "images/logW3.png", "images/logW2.png", "images/logW1.png"];

var en4:ClassEnemylog

en4=

new ClassEnemylog(urls16,1,6,300,256,480,0,2,96,32,10);

en4.addEventListener(

"image_loaded",imageLoadedHandler);

canvas1.addChild(en4);

myEnemyList12.push(en4);

/////

for each (var el:String in urls) {

var loader:Loader = new Loader;

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

loader.load(

new URLRequest(el));

}

private function imageLoaded(event:Event):void

{

var Singleimage:Bitmap = new Bitmap(event.target.content.bitmapData);

var bmd=Singleimage.bitmapData;

MyBData.push(bmd);

...

///////////////////// where it animates

public function moveLeft():void

{

if (_x<_endX -100 )

{

_x=_startX;

}

//_x-=_speed;

timej+=1;

if (timej>=32)

{

i=i + 1;

if (i>=_noFrames)

{i=0;}

img1.bitmapData=MyBData; ///////////////this is the issue

trace("in animate=" + i + " timej=" + timej + " _noFrames=" + _noFrames + "length=" +MyBData.length);

timej=0;

}

img1.x=_x;

}

This topic has been closed for replies.
Correct answer Ned Murphy

The array is not the issue, the process you use to load is (unless I am missing something).

You appear to be using a for loop and an array to try to control the loading order of images (though I'm not clear on where "urls" came from in

for each (var el:String in urls) {).  If you need things to be loaded in order, a for loop will not work... you need to load sequentially, meaning you load one file and upon completion of loading you load the next in line.

(WOW!!! three of us at once!!!)

3 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
November 12, 2010

The array is not the issue, the process you use to load is (unless I am missing something).

You appear to be using a for loop and an array to try to control the loading order of images (though I'm not clear on where "urls" came from in

for each (var el:String in urls) {).  If you need things to be loaded in order, a for loop will not work... you need to load sequentially, meaning you load one file and upon completion of loading you load the next in line.

(WOW!!! three of us at once!!!)

kglad
Community Expert
Community Expert
November 12, 2010

(i like my answer best.   LOL)

jagguy999Author
Known Participant
November 12, 2010

ok so I was loading in parallel so I changed my code and it works.

there is no serial loading function?

....

loadNext();

}

private function loadNext():void {

var loader:Loader = new Loader;

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

if(nextIndex < urls.length){

loader.load(

new URLRequest(urls[nextIndex++]));

}

}

private

function imageLoaded(event:Event):

void

{

var Singleimage:Bitmap = new Bitmap(event.target.content.bitmapData);

var bmd=Singleimage.bitmapData;

MyBData.push(bmd);

loadNext();

}

kglad
Community Expert
Community Expert
November 12, 2010

1.  loading is asynchronous

2.  for-loops cannot be used to display a sequence

3.  there's no code shown that would display a sequence of your loaded images.

Inspiring
November 12, 2010

It is natural because loading is asynchronous.