Help with buttons in AS3
Copy link to clipboard
Copied
Hi Folks,
I'm stuck with a simple flash movie I need to create in which two images fade in and fade out, and each of them must be clickable and hyperlink to a separate URL.
I've got the fading going okay, but I cannot for the life of me get even a single button to work on it.
If it's helpful I can send along what I've got so far. Any assistance would be greatly appreciated.
Regards,
Andrew.
Copy link to clipboard
Copied
In AS3, to make a button work with code, you need to add an event listener for it. In the timeline that holds that button, in a separate actions layer that you create, in a frame numbered the same as where that button exists, you would add the event listener:
btn1.addEventListener(MouseEvent.CLICK, btn1Click);
Descriptively, that line of code contains the following:
buttonInstanceName . displayObjectMethod (eventClass . eventType, eventHandlerFunction);
The name of the function for processing the clicking of that button was already defined at the end of the event listener assignment, so now you just have to write that function out:
function btn1Click(evt:MouseEvent):void {
var url:String = "http://www.awebsite.com/awebpage.html";
var req:URLRequest = new URLRequest(url);
navigateToURL(req);
}
Copy link to clipboard
Copied
Hi Ned,
Thank you for the followup email.
I think I was close - I was aware of the changes between AS2 and AS3, but I
think I was putting the Action in the wrong place.
Next question - if I have 2 buttons (say btn1 and btn2), how do I make btn1
available for say frames 1-60, and btn2 available from frames 61-120?
I am primarily a ColdFusion developer, and a complete newbie to flash, so
sorry if this is a dumb question.
Regards,
Andrew.
2009/5/15 Ned Murphy <forums@adobe.com>
In AS3, to make a button work with code, you need to add an event listener
for it. In the timeline that holds that button, in a separate actions layer
that you create, in a frame numbered the same as where that button exists,
you would add the event listener:
>
btn1.addEventListener(MouseEvent.CLICK, btn1Click);
>
Descriptively, that line of code contains the following:
>
buttonInstanceName . displayObjectMethod (eventClass . eventType,
eventHandlerFunction);
>
The name of the function for processing the clicking of that button was
already defined at the end of the event listener assignment, so now you just
have to write that function out:
>
function btn1Click(evt:MouseEvent):void {
var /String = "http://www.awebsite.com/awebpage.html";
var req:URLRequest = new URLRequest(url);
navigateToURL(req);
}
>
Copy link to clipboard
Copied
One way would be to go to the layer that has btn1, right click on frame 59 and select Insert Frame... that will make btn1 extend from 1 thru 59. Then, on a separate layer, insert a blank keyframe at frame 60, place btn2 on the stage while that frame is selected, and extend it to frame 120 the same way you just did for btn1. The code for btn2 would need to be in frame 60.
Another way would be to have both buttons in frame 1 with the code for both buttons also in frame 1 (different layer preferably). Then you would control the visibility of the buttons such that... in frame 1...
btn1.visible = true;
btn2.visible = false;
and in frame 60...
btn1.visible = false;
btn2.visible = true;
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.
Copy link to clipboard
Copied
Hi Ned,
Thanks for your help with this - the first solution worked great for me.
Best regards,
Andrew.

-
- 1
- 2