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

Converting an Actinscript code to Javascript for HTML 5 canvas.

New Here ,
May 11, 2017 May 11, 2017

I'm working on an animation on action script through Animate CC and need to convert it to HTML 5 canvas which I have done. Issue being the only code format I am having trouble converting to java script is the following :

stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);

function keyDownListener(e:KeyboardEvent){

if (e.keyCode == Keyboard.RIGHT) {

nextFrame();

}

if (e.keyCode == Keyboard.LEFT) {

prevFrame();

}

}

If anyone can help me if would be much appreciated as this is mainly needed for a web browser. TIA.

728
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 , May 11, 2017 May 11, 2017

window.onkeydown = keyDownListener.bind(this);

function keyDownListener(e){

if (e.keyCode == 39) {

this.gotoAndStop(this.currentFrame+1);  // you should be doing frame limit checking

}

if (e.keyCode == 37) {

this.gotoAndStop(this.currentFrame-1); // you should be doing frame limit checking

}

}

Translate
Community Expert ,
May 11, 2017 May 11, 2017

window.onkeydown = keyDownListener.bind(this);

function keyDownListener(e){

if (e.keyCode == 39) {

this.gotoAndStop(this.currentFrame+1);  // you should be doing frame limit checking

}

if (e.keyCode == 37) {

this.gotoAndStop(this.currentFrame-1); // you should be doing frame limit checking

}

}

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 ,
May 12, 2017 May 12, 2017

Thank you for your response kglad but I have tried to copy your code and use it on a web browser and it doesn't allow me to move my characters at all.

I'll show you a screen shot of my action script code on my other file. Screenshot (68).png

If you are able to send me through another type of code or give me advice on maybe how to format it properly then it would be much appreciated.

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 ,
May 12, 2017 May 12, 2017

that's not the code i suggested.  reread message 1.

in addition,

stop()

should be

this.stop()

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 ,
May 12, 2017 May 12, 2017

so what does your first message mean exactly? please bare with me as this is my first time using flash. does your code suggest to change certain formats on the HTML 5 canvas?

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 ,
May 12, 2017 May 12, 2017

there's nothing related to formatting or formats.

this is the code if you want to start with your timeline stopped.  is there any line of the code that you do not understand?

this.stop()

window.onkeydown = keyDownListener.bind(this);

function keyDownListener(e){

if (e.keyCode == 39) {

this.gotoAndStop(this.currentFrame+1);  // you should be doing frame limit checking

}

if (e.keyCode == 37) {

this.gotoAndStop(this.currentFrame-1); // you should be doing frame limit checking

}

}

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 ,
May 13, 2017 May 13, 2017

if (e.keyCode == 39) {

this.gotoAndStop(this.currentFrame+1);  // you should be doing frame limit checking

In that section of the code,  am I supposed to add in how many frames in total my animation is since my movie clip moves by each frame ?

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 ,
May 13, 2017 May 13, 2017

yes.  i would do this:

if (e.keyCode == 39 && this.currentFrame<this.totalFrames) {

this.gotoAndStop(this.currentFrame+1);

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 ,
May 13, 2017 May 13, 2017

only after adjusting the code on the HTML5 canvas and it works! thank you very much for your help, its taken a load of my mind for this 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 ,
May 13, 2017 May 13, 2017
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