?
Solved

Flash CS4/AS 3.0 Array question

Posted on 2009-02-13
12
Medium Priority
?
698 Views
Last Modified: 2013-11-12
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
Comment
Question by:1Cougar
  • 7
  • 5
12 Comments
 
LVL 9

Expert Comment

by:pepsichris
ID: 23635494
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
 

Author Comment

by:1Cougar
ID: 23639516
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
 
LVL 9

Expert Comment

by:pepsichris
ID: 23640314
You need to tell it what the LoaderInfo is, eg:

MovieClip((e.target as LoaderInfo).loader)
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Author Comment

by:1Cougar
ID: 23641375
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
 
LVL 9

Expert Comment

by:pepsichris
ID: 23641385
Sorry - I wasn't very specific...

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

Author Comment

by:1Cougar
ID: 23641455
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
 

Author Comment

by:1Cougar
ID: 23641489
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
 
LVL 9

Expert Comment

by:pepsichris
ID: 23641495
Sorry - last thing I wrote was rubbish! I wrote it in a rush.

Try:

gifArray.push(MovieClip((e.target as LoaderInfo).loader))
0
 

Author Comment

by:1Cougar
ID: 23641667
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
 

Author Comment

by:1Cougar
ID: 23641690
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
 
LVL 9

Accepted Solution

by:
pepsichris earned 2000 total points
ID: 23642019
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
 

Author Comment

by:1Cougar
ID: 23642529
yes, that did the trick!  Thanks so much for your patience and help!

Cheers!
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question