|
#1
|
||||
|
||||
|
infinite Duplicate MovieClips
I would like to create many duplicates of a movieclip. Also, upon creation of each movieclip, i would like to set a few properties.
For the new MC name, i would use "MC" + i, and update the value of i each time. but, i dont know how to call the unique MC's. _root."MC"+i._x obviously doesn't work, so... ...I tried creating an array, but i think my code was a little screwed up. Can someone explain how I might be able to modify many duplicates with and without an array? |
|
#2
|
||||
|
||||
Actionscript:
var gap:Number = 10;
for (var i = 0; i < 10; i++)
{
// you can use array access notation like this
_root["MC" + i]._x = i * gap;
// or you can use the eval() function like this
eval("MC" + i)._x = i * gap;
}
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius Blog | Shared Items |
|
#3
|
|||
|
|||
|
a shorter method
Here's another approach. A shortcut method without the need of using arrays. You can set movieclip properties while creating duplicate movie by setting parameters in the initObject.
This'll both duplicate a movieclip named "originalMC" AND place it at _x 200 and _y 100. Actionscript:
var myDupe:MovieClip = originalMC.duplicateMovieClip("myDupe", 0, {_x:200, _y:100});Additionally, you can also set properties now by using the myDupe variable because it contains a reference to the duplicate instance. Actionscript:
var myDupe:MovieClip = originalMC.duplicateMovieClip("myDupe", 0, {_x:200, _y:100});
myDupe._width = 350; //set the width of duplicate instanceTo use it in a loop using the loop from Scottae's array example: Actionscript:
var gap:Number = 10;
for (var i = 0; i < 10; i++) {
var myDupe:MovieClip = originalMC.duplicateMovieClip("MC"+i, i, {_x: i*gap});
//
// You can also set properties through myDupe
// because myDupe is referencing "MC"+i
myDupe._alpha = 50; //set every duplicate instance's alpha to 50%
}This will now move every duplicate instance by _x 10 and set the alpha at 50%. So there you go. You set the properties of the movieclip within the same line when you duplicate the movie, OR by manipulating the properties of the duplicate movieclip variable that holds the duplicate instance, "myDupe" in this case. This often makes it easier for me, rather than using the explicit references to arrays, like _root["MC" + i], as it is easy to get errors or forget the proper syntax. |
|
#4
|
||||
|
||||
|
would this work?
i want to randomly display a new instance of a movieclip over time. each second or few seconds, a new clip will be created.
...that and set a random x position and alpha value for each. how would i get movieclips to appear over time?? right now, i have code on a single movieclip called "tree" on the stage. the code says: Actionscript:
onClipEvent (enterFrame) {
a = Math.random()*150;
if (a<148) {
newXPosition = Math.random()*250;
this.duplicateMovieClip("tree"+i, 0);
_root.treesArray["trees"+i]._x = newXPosition;
}
}Last edited by Scottae : 01-21-2005 at 08:32 PM. Reason: Format with AS tags |
|
#6
|
||||
|
||||
|
Well, you should have said you wanted that in the first place so we didn't have to do all this beating around the bush. Here's an example of how you can do it.
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius Blog | Shared Items |
|
#8
|
||||
|
||||
|
Change the interval value.
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius Blog | Shared Items |
|
#9
|
||||
|
||||
|
sorry, i need to be more complete when i post
is it possible to have varied intervals between each movie clip's creation? the time in between each duplication would be different..? sorry about all the confusion! |
|
#10
|
||||
|
||||
|
I guess you could use Math.random(), or if you want specific values, maybe set them to an array and each time you set an interval, use the next value from the specified index of the array. Of course, each time you do this you need to clear the previous interval and then set another interval.
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius Blog | Shared Items |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| duplicate movieclip holder | bugjuice | Flash MX ActionScript |
1 | 02-19-2004 11:48 AM |
| can't remove duplicated movieclips | gaz_the_mod | Flash MX ActionScript |
1 | 02-17-2004 01:00 PM |
| sortOn() on an array of MovieClips: problem | aLearnerRather | Flash MX ActionScript |
3 | 01-06-2004 09:28 PM |
| duplicate _level problem | zorro_m2h | Newbies |
0 | 09-15-2003 05:52 AM |
| Duplicate movieclips BUT... | jeff2000 | Flash 5 Actionscript |
4 | 11-10-2001 06:50 AM |
All times are GMT. The time now is 01:43 PM.



TODAY'S POSTS
Flash Coding



