2

How do I convert these AS2 Buttons to AS3?

on (press) {
    nextFrame();
}
on (press) {
    prevFrame();
}
Dan Lew
  • 85,990
  • 32
  • 182
  • 176

6 Answers6

6
import flash.events.MouseEvent;

this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

public function mouseDownHandler(event:MouseEvent):void{
    nextFrame();
}

But you should probably also read this to learn how the event model has changed:

http://www.flashvalley.com/fv_tutorials/mouse_events_in_actionscript_3.0/

quoo
  • 6,237
  • 1
  • 19
  • 36
1

//I see you are doing non OOP so do this, place this on second frame. Modify it to your liking. Make sure you have the button throughout the timeline without it missing anywhere. Just move it off screen if you have tweens.

import flash.display.MovieClip;
import flash.events.MouseEvent;

urlbutton.addEventListener(MouseEvent.CLICK, urlfunc); 
urlbutton.useHandCursor = true; 


function urlfunc(myEvent:MouseEvent){ 
    var request:URLRequest = new URLRequest("siteurl");
    navigateToURL(request, "_blank");
    } 

continuebutton.addEventListener(MouseEvent.CLICK, continuefunc); 
continuebutton.useHandCursor = true; 

function continuefunc(myEvent:MouseEvent){ 
    gotoAndPlay('playgame');
    } 
jjwallace
  • 168
  • 2
  • 16
1
import flash.events.MouseEvent;

...

buttonA.addEventListener(MouseEvent.CLICK, onPressPrev);
buttonB.addEventListener(MouseEvent.CLICK, onPressNext);

private function onPressPrev(e:MouseEvent=null):void{
    prevFrame();
}
private function onPressNext(e:MouseEvent=null):void{
    nextFrame();
}

private function prevFrame():void{
    gotoAndStop(currentFrame-1)
}
private function nextFrame():void{
    gotoAndStop(currentFrame+1)
}

hope this helps some. seems like the question is already answered as far as the new MouseEvent structure.

SketchBookGames
  • 464
  • 8
  • 14
1

AS3 has changes a fair bit if you are used to "on(press)" button code.

This is the perfect video tutorial for you: Getting Started with AS3 - Simple Buttons. It explains the basics of buttons in AS3 for people who are coming from AS2. This should give you a good overview.

Adam Harte
  • 10,369
  • 7
  • 52
  • 85
0

For AS2, I have been using this code.

on(release){
    gotoAndStop(2);
{

For AS3

LIST.addEventListener(MouseEvent.CLICK, Button)


function (Button)(evt:MouseEvent){
    gotoAndStop(2)
}

So for where it says (Button) that is the name of the function and the button name.

Jake F.
  • 141
  • 1
  • 3
  • 17
0

shortest way of writing a button event handler is like this

var btn:SimpleButton;

btn.addEventListener(MouseEvent.CLICK,function(e:MouseEvent):void{
    //do your code for the click here
    nextFrame();
});
mihai
  • 4,184
  • 3
  • 26
  • 27