Buttons
Ok, I’m going to use the Flash section of this site to display finished work, but I’ll also use it for code snippets and other tips I discover as I work. I’ve just started using Actionscript 3, so it will be useful for me to have this stuff on hand, and hopefully useful for any of you who are also learning.
To start off with – buttons. Buttons have changed to fit with the event dispatcher model that AS3 uses extensively. Previously, a button link would be something like this:
button.onRelease = function():void {
// do something
};
Now, however, it need to be linked to an event, like so:
function buttonFunction(event:MouseEvent):void {
// do something
};
button.addEventListener(MouseEvent.CLICK, buttonFunction);
Otherwise if you want a cut-down version you can also drop the function into the button event:
button.addEventListener(MouseEvent.CLICK, function() {
// do something
});
This entry was posted on Thursday, May 28th, 2009 at 11:52 am and is filed under Flash. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.