Sign in to follow this  

(Solved) Need help translating AS2 code to HTML5

Recommended Posts


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);

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];


Anyone can help?

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)];

<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.