-
Function in a Function
I have this peice of code and all of it works except the bolded part, i cant figure out why, i thought it might have somthing to do with it being inside another function.
Code:
function RunBubble() {
var i;
for (i=0; i<BubbleCount; i++) {
if (_root.BubbleArray[i] == 1) {
if (_root["BubbleArray"+i].num == 1) {
_root["BubbleArray"+i]._y -= 5;
if (_root["BubbleArray"+i]._y<-10) {
_root["BubbleArray"+i].removeMovieClip();
_root.BubbleArray[i] = 0;
}
_root["BubbleArray"+i].onRollOver = function() {
_root["BubbleArray"+i].removeMovieClip();
_root.BubbleArray[i] = 0;
};
}
}
}
}
I know all the other stuff works because the bubbles move upwards and are removed at the top of the stage.
-
You can drop functions within functions ( I'm forever chaining onEnterFrames for quick and dirty fades ).
Not sure why your code isn't working, but you don't need to add the rollOver in a loop like that. When you first create your sprite just add the rollOver code then, rather than adding it every time you move each sprite.
Squize.
-
It's because the loop variable i does not exist inside the instance onRollOver scope, only in the RunBubble function scope.
I think you could attach vars, like _root["BubbleArray"+i].id = i; and then reference them later inside onRollOver with _root["BubbleArray"+this.id] = 0; Been a while since i've done this though, so not 100% sure on that :)
-
put the rollover action on the initial movie clip that you' copied.
-
Its kewl i spent an hour or so looking at the situation and i just decided to hittest my mouse to _root.BubbleArray[i] which works wonders :D..
Thanks any way people