Reputation:
How do I convert these AS2 Buttons to AS3?
on (press) {
nextFrame();
}
on (press) {
prevFrame();
}
Upvotes: 2
Views: 5345
Reputation: 141
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.
Upvotes: 0
Reputation: 168
//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');
}
Upvotes: 1
Reputation: 4214
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();
});
Upvotes: 0
Reputation: 516
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.
Upvotes: 1
Reputation: 10530
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.
Upvotes: 1
Reputation: 6307
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/
Upvotes: 6