Delegate works with plain old buttons too!

We’re working on a rush project and to save time are using our designer’s mock-up as a starting point (we usually re-create it from the ground up). One issue is that he occasionally uses plain old Flash buttons instead of Button components because you can’t instance skin a button on stage.

In order to work with these buttons we usually use a simple onRelease handler that calls a function on _parent, as in the following example.

buttonOne.onRelease = function() {
this._parent.buttonOneClick();
}

function buttonOneClick() {
trace("one");
}

But after a little experimenting we found that the new mx.utils.Delegate class included with the Flash MX 2004 7.2 Updater can be used with plain old Flash buttons too, not just components. The following example is a little cleaner.

import mx.utils.Delegate;
buttonTwo.onRelease = Delegate.create(this, buttonTwoClick);

function buttonTwoClick() {
trace("two");
}


Read more about Delegate in Mike Chamber’s article on DevNet.

Download the Flash MX 2004 7.2 Updater.

4 thoughts on “Delegate works with plain old buttons too!

  1. I’m Batsy,
    from UAE,
    and I’m 19 y.o

    Hi, Everyone
    I’ve studied English sinse this Winter .
    It’s Really difficult
    I would like like to meet boys and practisice My English with them.

    Thanks!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>