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

Help with buttons in AS3

Explorer ,
May 15, 2009 May 15, 2009

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.

TOPICS
ActionScript
3.8K
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
LEGEND ,
May 15, 2009 May 15, 2009

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);

}

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
Explorer ,
May 17, 2009 May 17, 2009

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);

}

>

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
LEGEND ,
May 17, 2009 May 17, 2009

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;

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
Explorer ,
May 19, 2009 May 19, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
LEGEND ,
May 19, 2009 May 19, 2009

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
Explorer ,
May 19, 2009 May 19, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 19, 2009 May 19, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 19, 2009 May 19, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 19, 2009 May 19, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 19, 2009 May 19, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 19, 2009 May 19, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 20, 2009 May 20, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 20, 2009 May 20, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 21, 2009 May 21, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 22, 2009 May 22, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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
Explorer ,
May 22, 2009 May 22, 2009

Hi Ned,

Thanks for your help with this - the first solution worked great for me.

Best regards,

Andrew.

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