trial Posted August 11, 2018 Share Posted August 11, 2018 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? Quote Link to comment Share on other sites More sharing options...
Milton Posted August 11, 2018 Share Posted August 11, 2018 this.gotoAndPlay(rand); Quote Link to comment Share on other sites More sharing options...
charlie_says Posted August 11, 2018 Share Posted August 11, 2018 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" Quote Link to comment Share on other sites More sharing options...
tips4design Posted August 11, 2018 Share Posted August 11, 2018 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. Quote Link to comment Share on other sites More sharing options...
trial Posted August 11, 2018 Author Share Posted August 11, 2018 6 hours ago, Milton said: this.gotoAndPlay(rand); Thank you, this worked perfectly! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.