31
Jul
04

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 Responses to “Delegate works with plain old buttons too!”


  1. 1 rapid weight loss thermocarb cheap pill Oct 29th, 2004 at 1:23 pm

    Hello there,

    Iwas browsing the web and found this blog. Some interesting quotes. Keep them coming!

    Alice
    rapid weight loss thermocarb cheap pill

  2. 2 Max Power Dec 3rd, 2004 at 10:35 am

    Welcome Home Everyone Home

    Cya
    Max

  3. 3 Call Centre Application Dec 3rd, 2004 at 11:44 pm

    Hi Guys

    Thanks for taking the time posting. MSN have finally launch blogs, what was with the delay?
    Call Centre Application

    Cya
    Bruce

  4. 4 LitliGirL Dec 7th, 2006 at 7:41 am

    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!!!

Comments are currently closed.