0
votes

I have a code to make confetti in my first scene and I only need it to happen on the first scene but it's happening on all of the scenes. If I put a stop(); code at the end of Scene 1 on the keyframe for the code layer, it stops the entire movie, not the code. I've also tried removeMovieClip(); on the frame with the movie clip code and that didn't work.

I have one layer with the movie clip, and the movie clip has this code on it:

onClipEvent (load) {
    function reset() {
        //generate the random color
        R = random(256);
        G = random(256);
    B = random(256);
     colorHexString = R.toString(16)+G.toString(16)+B.toString(16);
    colorHex = parseInt(colorHexString, 16);
    hairColor = new Color(this);
    hairColor.setRGB(colorHex);
    //generates random movemtn onscreen
    xSpeed = random(3)+1;
     ySpeed = (Math.random()+1)*random(5)+1;
    if (ySpeed == 1) {
        ySpeed = (Math.random()+1)*random(5)+1;
    }
    direction = random(2)+1;
    //randomly places confetti at the top of the screen
    position = random(863)+1;
    _x = position;
    _y = 0;
    }
    reset();
}
onClipEvent (enterFrame) {
    //makes the confetti fall
    _y += ySpeed;
    directionChange = random(10)+1;
    if (directionChange == 1) {
    direction = random(2)+1;
    xSpeed = random(3)+1;
    }
    if (direction == 1) {
    _x += xSpeed;
    }
    if (direction == 2) {
    _x -= xSpeed;
    }
    if (_y>400) {
    reset();
    }
}

Then I have a layer right above that called control that has this code in the first keyframe:

 numConfetti = 100;
for (i=2; i<=numConfetti; i++) {
confetti1.duplicateMovieClip("confetti"+i, i+100);
}

This code was one I got online for confett effect, so I'm not completely up to par with knowing how to fix it, but I know the basics. Can you please tell me how I can get the action to stop at the end of scene 1, and not continue to run as the Flash movie progresses to the next scene?

thank you so much! Jenn

1

1 Answers

0
votes

You problem is pretty simple. This code

numConfetti = 100;
for (i=2; i<=numConfetti; i++) {
    confetti1.duplicateMovieClip("confetti"+i, i+100);
}

create 100 instances which is copy of confetti1 MovieClip. The dynamicly created instances are not frame dependent. They are constanly stays there you created it and this in your main timeline. You have two options here.

1.At the moment of creating instances place references to them inside array then you need your confetti disappear remove every of them with code. Here changes in your creation code.

numConfetti = 100;
conf=[];
for (i=2; i<=numConfetti; i++) {
    var newConf=confetti1.duplicateMovieClip("confetti"+i, i+100);
    conf.push(newConf);
}

Then you need delete them use:

 for (i=0; i<conf.length; i++) {
    conf[i].removeMovieClip();
}

2.You could isolate all your confetti inside MovieClip. Just put all your code inside new MC, and then place it on your stage. Now if MC appears on stage - you see your confetti. If you go somethere where your MC is not (second Scene), confetti disappeared.