PDA

View Full Version : Referencing Duplicated Movie Clip In Separate Code Block



Vexir
April 14th, 2007, 01:44 AM
I have the following code:


bubble_mc._visible = false;
var bubbleCount:Number = 40;
var vertMaxSpeed:Number = 10; // will be used in calculating maxiumum vertical speed for bubbles' movement

dupMovie = function () {
for (i=0; i<bubbleCount; i++) {
bubble_mc.duplicateMovieClip("bubble"+i+"_mc", i, {_x:Math.random()*bubble_mc._x, _y:Math.random()*bubble_mc._y, _visible:true});
with (eval("bubble"+i+"_mc")) {
_height = _width = Math.random()*bubble_mc._height;
}
}
};
dupMovie();

onEnterFrame = function() {
for(i=0; i<bubbleCount; i++) {
var randomSpeed:Number = Math.random() * vertMaxSpeed;
"bubble"+i+"_mc"._y += randomSpeed;
if ("bubble"+i+"_mc"._y < 28) {
delete "bubble"+i+"_mc";
bubble_mc.duplicateMovieClip("bubble"+i+"_mc", i, {_x:Math.random()*bubble_mc._x, _y:Math.random()*bubble_mc._y, _visible:true});
with (eval("bubble"+i+"_mc")) {
_height = _width = Math.random()*bubble_mc._height;
}
}
}
}


The problem is that Flash whines when I call


"bubble"+i+"_mc"._y += randomSpeed;

Because it won't let me reference the duplicated movie clips that way.. is there any other way to do this?

geoken
April 14th, 2007, 12:07 PM
Whenever I use for loops I need to name my mc's like this;

mc = this["bubble"+i]

then I use 'mc' whithin the looping code to point to my movie. Whenever I try to use mc = "bubble"+i or simply point directly to "bubble"+i, I run into issues.

Vexir
April 14th, 2007, 01:02 PM
Edit:// Yeah, misread, thanks that works.

There's probably a better way to do this though, my end goal here is to randomly generate about 40 bubbles on screen and then have them drift upwards at random speeds.. If they reach a certain _y, they disappear and a new one appears at the bottom to take its place.