lundi 30 septembre 2019

Go to random frame, excluding current frame

Here is my problem.

My main timeline has 3 frames. Each frame contains different movieClip.

I created a button, and when user clicks this button, I want a random movieclip to play.

But, I don't want to play the same movieClip again. So, when user is on the frame 1 and clicks the button, either frame 2 or 3 should play. Similarly, if the user is on the frame 2, frame 1 or 3 should play.

Now, I used this code and almost achieved what I wanted:

var _this = this;
_this.Play_button.on('click', function(){
_this.gotoAndStop(0+Math.random()*2);
});

But. Many times, the click on the button goes to the same frame, and this is not what I want.

Could someone here help me to achieve this? This is a HTML5 canvas, if it makes a difference.




Aucun commentaire:

Enregistrer un commentaire