Class org.as2lib.env.reflect.Delegate

org.as2lib.env.reflect.Delegate

Description

Delegate offers with Delegate.createDelegate a method for using old-style Template classes.

Using event handling like in common MovieClips creates problems in OOP ActionScript due to the fact that it uses functions as event executions without minding about that the scope always refers to the MovieClip. Delegate.createDelegate allows a proper Workaround for the redirection of such methods to a proper different scope.

Example:

Test class: class com.domain.MyMovieClipController { private var content:String; public function MyMovieClipController(content:String) { this.content = content; } public function onEnterFrame() { trace(content); } }

Usage: import com.domain.MyMovieClipController; import org.as2lib.env.reflect.Delegate; var mc:MyMovieClipController = new MyMovieClipController("Hello World!"); // Following will not work because of the wrong scope _root.onEnterFrame = mc.onEnterFrame; // Workaround using delegate _root.onEnterFrame = Delegate.createDelegate(mc, onEnterFrame);

Method Index

createDelegate(), createExtendedDelegate()

Method Detail

createDelegate

static public function createDelegate(scope, method:Function):Function

Creates a method that delegates its arguments to a certain scope.

Parameters

scopeScope to be used by calling this method.
methodMethod to be executed at the scope.

Return

Function that delegates its call to a different scope & method.

createExtendedDelegate

static public function createExtendedDelegate(scope, method:Function, args:Array):Function

Creates a method that delegates its arguments to a certain scope and uses additional fixed arguments.

Example: import org.as2lib.env.reflect.Delegate; function test(a:String, b:Number, c:String) { trace(a+","+b+","+c); } var delegate:Function = Delegate.createExtendedDelegate(this, test, ["a"]); delegate(1,"b"); // will trace "a,1,b"

Parameters

scopeScope to be used by calling this method.
methodMethod to be executed at the scope.
argsArguments to be used at first position.

Return

Function that delegates its call to a different scope & method.