Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-15-2005, 08:43 PM   #1
Dynamite Crash
Registered User
 
Join Date: Dec 2004
Posts: 17
Default Arrays of movie clips?

I have 12 Movie Clips setup and I have an XML file that I'm reading information from. In the XML file there will be 12 separate URL's for images that are suppose to be loaded into the movie clips. To do this I'm trying to use a for loop to populate the movie clips, but the problem is I want to have just a single statement in the for loop instead of like 12.

So I'm wondering how arrays of movie clips work (if they do) and how you create them or reference different ones. Currently they're all given the name clip and i'm trying something like this:
Code:
for (var i:Number = 1; i <= TotalMovieClips; i++){
    clip[i].loadMovie(myXML.firstChild.childNodes[1].childNodes[i].firstChild);
}
But that code fails so I assume this isn't how you reference an array of movieclips. I'm also having trouble resizing the movie clips after I tell it to load in an image. I know it has to wait until the image is fully loaded so it can be resized but getting it to function like that is giving me problems.

Anyone have any suggestions?
Dynamite Crash is offline   Reply With Quote
Old 02-16-2005, 05:42 AM   #2
tris
Registered User
 
Join Date: Nov 2004
Posts: 163
Default

first off the way you are accessing the clip array is fine. But are you sure you're accessing your XML correctly? you could test by doing: trace(myXML.firstChild.childNodes[1].childNodes[i].firstChild)

I recommend using a MovieClipLoader to load the clips if you want resize them after loading. You can assign a onLoad event listener to the load so once its loaded you can resize / position etc that way you can also create a loading bar etc.
tris is offline   Reply With Quote
Old 02-16-2005, 08:36 AM   #3
pcarini
Shameless Audiophile
 
pcarini's Avatar
 
Join Date: Aug 2004
Posts: 129
Default

An array shouldn't function any differently for a MovieClip than for anything else. You might wanna try tracing clip[i] to see if it doesn't show up as undefined. If so, you haven't created those MovieClips in the first place, or haven't fed them into the array correctly.

I usually have a much easier time when I push mc's to an array right when I create them.

ActionScript Code:
for(var i=0; i<TotalMovieClips; ++i) {    clip.push( createEmptyMovieClip(etc, etc) );     // or clip.push( (any other function that returns a movieClip) ) }

As far as resizing them after the fact, Tris is right.. MovieClipLoader and the onLoadComplete event handler is the easiest way.
pcarini is offline   Reply With Quote
Old 02-17-2005, 03:36 PM   #4
Dynamite Crash
Registered User
 
Join Date: Dec 2004
Posts: 17
Default

Hmm...I'm hearing what you're saying but I just can't get it to implement. When I try tracing clip[i]._name in the for loop it says undefined. It did this both before and after I tried using your system. Although I will say that I changed it some and could have messed it up.

This is the code I have setup in frame 1:

PHP Code:
var myXML:XML = new XML();            
myXML.load("results.xml");            
myXML.onLoad LoadThumbnails;

/**************************************/
/* Loads initial images into the MC's */
/**************************************/

function LoadThumbnails():Void {
    
    for(var 
i=0i<TotalMovieClipsi++){
      
this.push(createEmptyMovieClip("clip"this.getNextHighestDepth() ) );
        
clip[i].loadMovie(myXML.firstChild.childNodes[1].childNodes[i].firstChild);
        
trace(clip[i]._name);
    }

I removed a trace statement that checked to make sure it was accessing the XML file correctly and the trace statement did provide the URL of the image. Where you see the createEmptyMovieClip, I also tried this.createEmptyMovieClip to the same result.

As far as the MovieClipLoader, how would that work if I'm creating regular movie clips? Or is it possible to still use a MovieClipLoader with an already created MovieClip?

Sorry I'm a relative noob at this.
Dynamite Crash is offline   Reply With Quote
Old 02-17-2005, 09:44 PM   #5
pcarini
Shameless Audiophile
 
pcarini's Avatar
 
Join Date: Aug 2004
Posts: 129
Default

To avoid any extra messiness I did this all on frame 1, in an empty flash movie. It works. If all your images were the same size, you'd only see one, because they start in the same place. That'd be easy to change that in code, though.

ActionScript Code:
stop(); // Arrays must be created using new before you push stuff into them var urlArray:Array = new Array("./test1.jpg", "./test2.jpg", "./test3.jpg", "./test4.jpg", "./test5.jpg"); var clipArray:Array = new Array(); // Also, the clip name (e.g. "clip"+i here) needs to be unique.  // If I left off the +i, I'm pretty sure that each loop would overwrite the previous clip w/ the new one. for(var i=0; i<urlArray.length; ++i)     clipArray.push( _root.createEmptyMovieClip( "clip"+i, _root.getNextHighestDepth()) );     //trace(clipArray); for(var j=0; j<urlArray.length; ++j) {     clipArray[j].loadMovie(urlArray[j]); } trace(clipArray); // Both traces: _level0.clip0,_level0.clip1,_level0.clip2,_level0.clip3,_level0.clip4 // but the pics are now loaded in and visible on the root level.

Hope it helps some.
-C
pcarini is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:30 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.