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

Can't add action on a button

New Here ,
Apr 29, 2011 Apr 29, 2011

I use to be able to create a button in flash 8 and add an action on it such as “geturl”. Now that I am in Flash CS3, the action panel tells me “current selection cannot have actions apply to it”. This does not make any sense, how can I add action to my button now ?

TOPICS
ActionScript
5.4K
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

correct answers 1 Correct answer

LEGEND , Apr 29, 2011 Apr 29, 2011

Here's a little cut and paste regarding AS3 Button Code
--------------------------

Let's say you create a button symbol.  Since it is a button, it is already a self animating object that will react to mouse interactions, but only visually at this stage.  The first thing you need to do to make it useful code-wise is to assign it a unique instance name.  So you drag a copy of it out to the stage from the library, and while it's still selected, you enter that unique instance name for it in the Proper

...
Translate
LEGEND ,
Apr 29, 2011 Apr 29, 2011

In an AS3 file you can no longer apply code directly onto objects.  The code either goes into the timeline or in separate actionscript/class files.

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
New Here ,
Apr 29, 2011 Apr 29, 2011

I tried to go to another of your answer for that guy with the learnmore_btn.

But I get a message as follow : 1120: Access of undefined property learnmore_btn. I did rename my bitton learnmore_btn in the property panel.

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 ,
Apr 29, 2011 Apr 29, 2011

Here's a little cut and paste regarding AS3 Button Code
--------------------------

Let's say you create a button symbol.  Since it is a button, it is already a self animating object that will react to mouse interactions, but only visually at this stage.  The first thing you need to do to make it useful code-wise is to assign it a unique instance name.  So you drag a copy of it out to the stage from the library, and while it's still selected, you enter that unique instance name for it in the Properties panel... let's say you name it "btn1"


In AS3, to make a button work with code, you need to add an event listener and event handler function for it.  You might need to add a few (for different events, like rollover, rollout, clicking it, but for now we'll just say you want to be able to click it to get a web page to open.  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);

The name of the unique function for processing the clicking of that button is specified 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);

}

Here's some of what's involved there:


evt:MouseEvent - the event listeners throws an argument automatically which the function must be set up to receive.  In this case I have given that argument a variable name of evt, though I could have chosen anything.


:void - this defines the class of the value that the function will return.  In this case, the function does not return anything, so "void" is used.  If it did return a value, you would see a line containing "return xyz"; in the function (where xyz is not literal, it simply represents the variable or value being returned)


The normal code to open a web page contains three distinct elements, the url, the request, and the command to get the page, so I have shown them as three separate lines.  Many people will combine them into one line...

 

function btn1Click(evt:MouseEvent):void {

   navigateToURL(new URLRequest("http://www.awebsite.com/awebpage.html"));

}

In AS3, in strict mode, it is necessary to identify the types/classes of the variables being created, which is why you see :String, :MouseEvent, etc... showing up everywhere.


I know that's probably clear as mud in the explanation, but hopefully it will shed some light on what you're working with.


Now, to create another button with a unique function for it, you could just drag another copy of it from the library, give it a unique name, say btn2, copy/paste the code from btn1 and replace "btn1" with "btn2" in that copied code, adding a new url for the page that button will open.

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
New Here ,
Apr 29, 2011 Apr 29, 2011
Did they make this complicated so only programmer should be able to use Flash, it use to be so simple.
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 ,
Apr 29, 2011 Apr 29, 2011

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
New Here ,
Apr 29, 2011 Apr 29, 2011

Ok now it seem I somewhat got it.

For the clicktag now, can I use an invisible button on top of the whole animation where the code mught be : on (release) {

getURL(clickTAG, "_blank");

}

This is what I used to do.
Thank you.
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
New Here ,
Apr 29, 2011 Apr 29, 2011

If I can't make it work, I am staying with version 8, this will resolve the issue. Would that be that bad to still use 8 for such simple stuff ?

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
New Here ,
Apr 29, 2011 Apr 29, 2011

Also, how to have the link open in self window instead of blank ? It seem it opens it in blank by default, in version 8 I used to be able to choose myself.

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
Mentor ,
Apr 29, 2011 Apr 29, 2011
LATEST

Use _self, instead of _blank

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