0

I have this code in Actionscript 3, but have to write it in Javascript:

pressButton.addEventListener (MouseEvent.CLICK, press_button);  

function press_button (event:MouseEvent) :void 
{ 
       gotoAndPlay(2); 
}   

I need for Createjs.

Thanks

2
  • 3
    This site isn't about people writing/rewriting your code in another language, at least provide your own attempt first Commented Sep 30, 2013 at 17:14
  • Also JavaScript doesn't have the concept of 'frames' built in. Commented Oct 1, 2013 at 4:29

1 Answer 1

1

3 things:

  1. JS does not support typing (ex. event:MouseEvent)
  2. EaselJS does not include event constants (ex. MouseEvent.CLICK)
  3. you need to use explicit scoping in JS

So, you could rewrite it to this, using "bind" to establish your callback scope:

pressButton.addEventListener("click", press_button.bind(this));
function press_button(event) {
  this.gotoAndPlay(2);
}

Or, you could take advantage of the "on" shortcut in EaselJS v0.7.0 to handle scoping:

pressButton.on("click", press_button, this);
function press_button(event) {
  this.gotoAndPlay(2);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Still struggling! and more confused, maybe I didn't explain but the "pressButton is the name of the instance on the stage in Flash & "press_button" is the name of the function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.