Skip to main content
biota
Participant
January 5, 2015
Answered

convert as3, to java script

  • January 5, 2015
  • 1 reply
  • 1045 views

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

}

This topic has been closed for replies.
Correct answer kglad

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

}

*/


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.

1 reply

kglad
Community Expert
Community Expert
January 5, 2015

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

}

biota
biotaAuthor
Participant
January 5, 2015

thanks, but does not work..

i don't want to use as3, only js for a canvas project.

kglad
Community Expert
Community Expert
January 5, 2015

use:

var tl=this;

myFunction();

function myFunction() {

tl.gotoAndPlay(Math.floor(Math.random() * 149) + 2);

}