Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

convert as3, to java script

New Here ,
Jan 05, 2015 Jan 05, 2015

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

}

TOPICS
ActionScript
991
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 05, 2015 Jan 05, 2015

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.

Translate
Community Expert ,
Jan 05, 2015 Jan 05, 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2015 Jan 05, 2015

thanks, but does not work..

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2015 Jan 05, 2015

use:

var tl=this;

myFunction();

function myFunction() {

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2015 Jan 05, 2015

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

}

*/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2015 Jan 05, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2015 Jan 05, 2015

It works!

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2015 Jan 06, 2015
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines