PDA

View Full Version : Trying to make a simple button


GaleForce
11-03-2007, 04:55 AM
I've been searching through the vast internet for hours on how to make a button in AS3. All results I've found have not been quite what I was looking for, as in maybe the syntax was right but it required me to make a separate AS file. Whatever the reason was, nothing satisfied my problem, but I'm the closest I've been yet to getting the button to work.

What the button should do: gotoAndStop("particle")
particle is what I named the destination frame
I have a button symbol, instance name cloud7
I don't want to use a movie clip
I don't want to have to make a separate AS file
I want to do ALL the programming for the button in the button's frame

Here is my code so far;

import flash.events.MouseEvent;

cloud7.addEventListener(MouseEvent.CLICK,cloudSeve nClick);
function cloudSevenClick(Event:MouseEvent)
{
gotoAndStop("particle");
}


When I try to compile this I get, as expected, an error in regards to 'cloud7' being undefined. The specific error is "1120: Access of undefined property cloud7." I've tried defining it with the code;

var cloud7:Button = new Button();

However AS3 has no idea what 'Button' is despite it being in the drop down menu of items you can place after "var cloud7:". I've searched everywhere for what to import so that the compiler knows what 'Button' is, however I can't find it.

So basically I need help finishing this code. I'm guessing if I can find the right file to import than my original defining code would work, but if anyone else has another suggestion please let me know. Thanks!

EDIT: Also, I know I can use the SimpleButton() function and define sprites for each of the four button states, but I've already put a lot of work into the button states in my actual button symbol. It has multiple images and sound clips so switching to the sprite method at this point would be a real headache.

Vjeko
11-03-2007, 07:58 AM
Go to .fla file and right click on your button (which you want to make a button) in the library, select Linkage, and then check box "Export for Actionscript".
Then you should write it's class name (I suppose cloud7), and click OK.

In your as file, add line:
import cloud7;

Then you can create instances of your button like:
var cloud7_btn:cloud7 = new cloud7;

Hope it helped,
Vjeko

GaleForce
11-03-2007, 09:31 AM
I tried your method out but I couldn't get it to work. I'm not exactly sure what you mean by my "as file." I don't know if there is a default as file somewhere or you mean the frame.

Anyways...

Well I figured out one of my biggest issues. When I click a symbol (in this case, the button) and give it an instance name, that frame's action script doesn't recognize the instance name. As said earlier I get a 1120 error because to the action script the phrase "cloud7" is an undefined property, despite cloud7 being the instance name of a button in the frame.

All of my code works, its just this issue of instance names not being recognized.

GaleForce
11-03-2007, 09:56 AM
Meh, just forget it. For a small, simple project like this, AS2 is much easier to use. Got it working right away with that.