Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating buttons from Symbol versus Component 1

Status
Not open for further replies.

snakehips2000

Programmer
Nov 10, 2003
95
GB
Why, when I add actionscript to a button created from a symbol, do I have to apply the code to the "On Release" event of the button to get it to work? Creating an event listener on the main timeline just ignores my code. Here's the example I'm using ...

I have a button created from two graphic symbols. I have designated the Up, Over, Down and Hit states, dragged an instance of the button to the stage and called it "btn". The states act as they ought but the action below is ignored:

var TestListener:Object = new Object();
TestListener.click = function() {
trace("hello")
}
//add the event listener to the button
btn.addEventListener("click", TestListener);

If I drag a button component to the stage and apply the listener to that instance - no problem.
 
Button does not dispatch "click" event like components, you cannot use Listener object like that.

You can do simply:

[tt]//
btn.onPress = function():Void {
trace("hello");
};
//[/tt]

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top