mercredi 20 septembre 2017

Making a button that goes to a random frame (from an array) on the main timeline. How to do from a movie clip?

I saw plenty of questions that asked how to make a button in a movie clip that leads to a frame in the main timeline, and took a look at them. But is it different if you want to go to a random frame in a specific set of frames? I've never really used AS3 aside from simple things like stop(); or gotoAndPlay.

Here's what my main timeline looks like at the moment: Figure 1

Here's the code I've got so far by using Google:

var frameB:Array=[1,28,45,56,71,91,106,126];
blue_circle1.addEventListener(MouseEvent.CLICK, choose);

function choose1(event:MouseEvent):void {
    var randomFrame:Number = frameB[Math.floor(Math.random() * frameB.length)];
    trace(randomFrame);
    gotoAndPlay(randomFrame);
}

The code works fine when I use it on the rotation buttons in the main timeline. But it doesn't work when I put it in a button in a movie clip. I need to change it so it works. If there is a better way of doing this, I'm willing to try it.




Aucun commentaire:

Enregistrer un commentaire