PDA

View Full Version : Buttons in Air


mousels
08-08-2008, 06:35 PM
Hi all

I've recently started learning how to develop desktop things using Flash CS3 and Air. However, I'm having some problems with the basics of the Air scripting.

Not sure if I've done something wrong, but I cannot add actionscript to any of the buttons I create.

What I'm wanting to do is create a button that I'm going to place in one of the corners. When the button is pressed I'm wanting it to do is run the nativeWindow.close piece of actionscript.

Am I able to add the code the the button as I normally (directly onto the button itself)? Or do I need to create a function that will locate the button and run the code when the button is pressed?

Any help is appreciated

mousels

evride
08-09-2008, 01:34 PM
Actionscript 3 (which is what AIR uses) no longer allows putting code directly on a button. instead give the object you want to add actions to an instance name. its in the properties panel. then you can use that instance name to add event listeners to and change the properties.


btn.addEventListener(MouseEvent.CLICK, buttonClick);
function buttonClick(evt:MouseEvent){
stage.nativeWindow.close();
}


notice also that .onPress is no longer used in Actionscript3. instead you add an event listener of an event type. here i used the MouseEvent.CLICK event.

mousels
08-09-2008, 02:14 PM
Thanks evdog! It all makes sense now.