View comments | RSS feed

Delegate class

Inheritance Object > Delegate

ActionScript Class Name mx.utils.Delegate

The Delegate class lets you run a function in a specific scope. This class is provided so that you can dispatch the same event to two different functions (see Delegating events to functions), and so that you can call functions within the scope of the containing class.

When you pass a function as a parameter to EventDispatcher.addEventListener(), the function is invoked in the scope of the broadcaster component instance, not the object in which it is declared (see Delegating the scope of a function). You can call Delegate.create() to call the function within the scope of the declaring object.

Method summary for the Delegate class

The following table lists the method of the Delegate class.

Property Description

Delegate.create()

A static method that allows you to run a function in a specific scope.


Comments


webweber@bluewin.ch said on Aug 12, 2004 at 10:01 AM :
> call the function within the scope of the declaring object.

In many situations - e.g. a View/Controller relationship - you will want to call an instance method of another class: the View contains the Delegate.create() statement which should proxy the event to a method of the Controller.

In this case you have to use this syntax:

Delegate.create(controllerInstance,controllerInstance. someMethod);
buntin12 said on May 26, 2005 at 6:44 AM :
Here's another example to clarify the use of normal non-component buttons. If anyone can find a better way please let me know.

public function makeTools ():Void {
var c = getController()
//Normal custom button
target.loginBtn.onRelease = function() { c.loginCalled(); }
//Button component
target.loginBtn2.addEventListener("click", Delegate.create(c, c.login2Called));
}

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00002400.html