Copy link to clipboard
Copied
Hi,
I want to convert as3 code from flash, to java script to use in the html5 canvas.
Any help please?
This is a as3 code:
var randNum:Number = Math.floor(Math.random() * 149) + 1;
var fixedFrame:Number = randNum + 1;
gotoAndStop(fixedFrame);
I try this but not working:
function myFunction() {
var randNum = Math.floor(Math.random() * 150) + 1;
var fixedFrame = randNum + 1;
_this.gotoAndPlay(fixedFrame);
}
you can't put that in the first frame and expect it to work. the frames further down the timeline probably haven't loaded, yet.
use the preload class to check.
Copy link to clipboard
Copied
use:
function myFunction() {
var randNum = Math.floor(Math.random() * 150) + 1; // this works the same in as3 as createjs/javascript so should be the same as your as3 code.
var fixedFrame = randNum + 1;
this.gotoAndPlay(fixedFrame);
}
Copy link to clipboard
Copied
thanks, but does not work..
i don't want to use as3, only js for a canvas project.
Copy link to clipboard
Copied
use:
var tl=this;
myFunction();
function myFunction() {
tl.gotoAndPlay(Math.floor(Math.random() * 149) + 2);
}
Copy link to clipboard
Copied
I tried it, but does not play, remains stopped in the first frame.
/* js
var tl=this;
myFunction();
function myFunction() {
tl.gotoAndPlay(Math.floor(Math.random() * 150) + 2);
}
*/
Copy link to clipboard
Copied
you can't put that in the first frame and expect it to work. the frames further down the timeline probably haven't loaded, yet.
use the preload class to check.
Copy link to clipboard
Copied
It works!
thanks
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now