• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 700
  • Last Modified:

Flash CS4/AS 3.0 Array question

Hello,

I am hoping someone can shed some light...I would like to preload 15 gifs and put them in an Array and then display them on the stage later.  I have the code below.  However, it only loads the last gif and puts it in the array, so there is only 1 gif in the array instead of 2.  I am not sure what to do...???

Thanks a lot!

Cheers!
var gifArray = new Array();
for(var i:Number=1; i<3; i++){
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("OC"+i+".gif"));
}
									
 
 
function done(e:Event):void
{
	gifArray.push(l);
	trace("Complete!! - " + i);
	gifArray[0].x = 100;
	addChild(gifArray[0]);
	addChild(gifArray[1]);
 
}

Open in new window

0
1Cougar
Asked:
1Cougar
  • 7
  • 5
1 Solution
 
pepsichrisCommented:
It's cos you're trying to add "l" o the array - add (e.target as LoaderInfo).loader instead, ie:

gifArray.push((e.target as LoaderInfo).loader);
0
 
1CougarAuthor Commented:
When I tried to substitute your code in my code below (that I finally got to work...), it throws an error:

ReferenceError: Error #1056: Cannot create property x on flash.display.LoaderInfo.
      at content_fla::MainTimeline/done()
Complete!! - 3
ReferenceError: Error #1056: Cannot create property x on flash.display.LoaderInfo.
      at content_fla::MainTimeline/done()

Your way seems much more elegant, but don't know what I did wrong....my code (that is working) is below.  Any ideas?

Thanks for your comments.
var loadArray = new Array();
var gifArray = new Array();
for(var i:Number=1; i<3; i++){
loadArray[i] = new Loader();
loadArray[i].contentLoaderInfo.addEventListener(Event.COMPLETE, done);
loadArray[i].load(new URLRequest("OC"+i+".gif"));
}
									
 
function done(e:Event):void
{
	for(var j:Number=1; j<3; j++){
	gifArray.push(loadArray[j]);
	}
	trace("Complete!! - " + i);
	gifArray[0].x = 100;
	gifArray[1].y = 100;
	addChild(gifArray[0]);
	addChild(gifArray[1]);
	//removeChild(gifArray[0]);
}

Open in new window

0
 
pepsichrisCommented:
You need to tell it what the LoaderInfo is, eg:

MovieClip((e.target as LoaderInfo).loader)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
1CougarAuthor Commented:
I'm sorry--you've lost me.  I don't know where to insert "MovieClip".  All I know is once my code has : gifArray.push (e.target as LoaderInfo, loadArray); it doesn't bomb, but I am unable to access the individual gifs from the array.  I cannot assign x values etc.  Then it throws the error above.  If I "trace(gifarray) with your line of code I get:

Complete!! - 3
[object LoaderInfo],,[object Loader],[object Loader]
Complete!! - 3
[object LoaderInfo],,[object Loader],[object Loader],[object LoaderInfo],,[object Loader],[object Loader]

I understand you told me to tell it it is a MovieClip, but I don't know where I have to do that.  

Thanks~
0
 
pepsichrisCommented:
Sorry - I wasn't very specific...

gifArray.push (MovieClip(e.target as LoaderInfo, loadArray));
0
 
1CougarAuthor Commented:
Just to add, I have tried:

gifArray.push(Bitmap(e.target as LoaderInfo), loadArray);

and

gifArray.push(MovieClip(e.target as LoaderInfo), loadArray);

And, I get the error :

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::LoaderInfo@413ef941 to flash.display.MovieClip.
      at content_fla::MainTimeline/done()
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::LoaderInfo@413ef821 to flash.display.Bitmap.
      at content_fla::MainTimeline/done()

I am loading gifs, so they are not MovieClips.  I would like to understand how to do it your way, but it seems I may just have to settle for doing it the way I got it to work--

If you can see what I am doing wrong, it would be much appreciated....

0
 
1CougarAuthor Commented:
Hi again,

Tried to copy and paste your code and I get an error:

1137: Incorrect number of arguments.  Expected no more than 1.
0
 
pepsichrisCommented:
Sorry - last thing I wrote was rubbish! I wrote it in a rush.

Try:

gifArray.push(MovieClip((e.target as LoaderInfo).loader))
0
 
1CougarAuthor Commented:
Hi,

I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@55d090e1 to flash.display.MovieClip.
      at content_fla::MainTimeline/done()
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@55d09191 to flash.display.MovieClip.
      at content_fla::MainTimeline/done()

0
 
1CougarAuthor Commented:
Hi,

Changed the code to :

gifArray.push(MovieClip((e.target as LoaderInfo).loadArray)), since my loader is name loadArray and I get the compile error:

1119: Access of possibly undefined property loadArray through a reference with static type flash.display:LoaderInfo.
0
 
pepsichrisCommented:
Sorry for wasting your time - I'm annoyed with myself now!

The following is actually tested!

gifArray.push(Bitmap((e.target as LoaderInfo).content));
0
 
1CougarAuthor Commented:
yes, that did the trick!  Thanks so much for your patience and help!

Cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now