Wednesday, September 5, 2012

Messenger and Interpreter Pattern AS3

Making a messenger design pattern in as3 should not be too hard:
Seeing that this is possible:

function doStuff():void
{
 trace("doStuff called");
}

var obj:Object = new Object();
obj["x"] = 100;
trace(obj.x);

obj["f"] = doStuff;
obj.f();
obj["f"]();

var fString:String = "f";
obj[fString]();

//output:
//100
//doStuff called
//doStuff called
//doStuff called

No comments:

Post a Comment