Sign in to follow this  
trial

(Solved) Need help translating AS2 code to HTML5

Recommended Posts

Hello,

I'm trying to translate this gotoAndPlay/array framelabel code from as2 into html5, but I'm not having much luck:

frameLabel = new Array()
frameLabel[0] = "repeat";
frameLabel[1] = "dontrepeat";

rand = random(frameLabel.length);
gotoAndPlay(frameLabel[rand]);

I got this html5 random array code from somewhere but couldn't make it work:

var frameLabel = ["repeat", "dontrepeat"];
var rand = frameLabel[(Math.random() * frameLabel.length) | 0];

this.gotoAndPlay(frameLabel[rand]);

Anyone can help?

Share this post


Link to post
Share on other sites

I think you may need to floor your random

var frameLabel = ["repeat", "dontrepeat"];
var rand = frameLabel[Math.floor(Math.random() * frameLabel.length)];
this.gotoAndPlay(rand);

<edit> or do what @milton said - I'd misread the "| 0"

 


 

Share this post


Link to post
Share on other sites
4 hours ago, charlie_says said:

I think you may need to floor your random


var frameLabel = ["repeat", "dontrepeat"];
var rand = frameLabel[Math.floor(Math.random() * frameLabel.length)];
this.gotoAndPlay(rand);

<edit> or do what @milton said - I'd misread the "| 0"

 



 

He already does it with the bitwise OR.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.