Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-19-2005, 03:21 AM   #1
epitts
Registered User
 
Join Date: Feb 2005
Location: Athens, GA
Posts: 2
Default for loop drops data

Hi, I'm new to AS loops and need help! I'm using loops to create duplicate movie clips.

There are two MCs on the stage: targetMC and otherMC. makeaLoop should loop through two functions: myLoop1 and myLoop2. Each of these functions loop to create duplicate movie clips, either targetMC 25x vertically or otherMC 25x horizontally.

While the trace shows that both loops are successful, only the MC in the second function is duplicated. If I switch the order, it always duplicates the MCs in the final function. Why is this?

ActionScript Code:
makeaLoop(); function makeaLoop(){     for (i=1; i<=25; i++) {         myLoop1();         myLoop2();     } } function myLoop1(){     for (k=1; k<=25; k++) {         duplicateMovieClip ("targetMC", "dupMC"+k, k);         _root["dupMC"+k]._y = 100 + (k*15);         trace("loop 1");     } } function myLoop2(){     for (j=1; j<=25; j++) {         duplicateMovieClip ("otherMC", "dupOtherMC"+j, j);         _root["dupOtherMC"+j]._x = 100 + (j*15);         trace("loop 2");     } }
Am I missing some key actionscript here? Eventually, I'll embed one loop inside the other to create a grid of clips 25 x 25, is there a better way to do this?

Any help will be appreciated.
epitts is offline   Reply With Quote
Old 02-19-2005, 03:25 AM   #2
Byronc
Digital Curmudgeon
 
Byronc's Avatar
 
Join Date: Feb 2005
Location: http://www.were-here.com
Posts: 58
Default

You are overwriting your clips by reusing the same depths for subsequent clips. Only one movieclip within a given timeline can occupy a specific depth; creating or duplicating another object to an already used depth destroys the object that previously existed there.

Recommendation, always start your loops and enumerations with 0, instead of 1 -- just makes programming a whole lot easier.
__________________
Byron “Barn” Canfield
Gone back to were-here.com where I need not tolerate oldnewbie's juvenile behavior.
Byronc is offline   Reply With Quote
Old 02-19-2005, 03:38 AM   #3
epitts
Registered User
 
Join Date: Feb 2005
Location: Athens, GA
Posts: 2
Default

You've just given me an "ah ha" moment. Now I understand the importance of the third duplicateMovieClip parameter: depth.

Thank you!!
epitts is offline   Reply With Quote
Old 02-19-2005, 04:44 AM   #4
Barn
digital curmudgeon
 
Barn's Avatar
 
Join Date: Feb 2005
Location: http://www.were-here.com
Posts: 1,082
Default

You're welcome. Ah, yes -- I love to hear those digital epiphany's (wasn't that a song by the Supremes? "I hear ephiphany").
Barn 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 07:50 PM.


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