Ok I have a pretty interesting situation… I am trying to use Flash’s BroadcasterMX class to create personalized “onWhatever” listeners for my classes. I got on this rabbit trail by picking apart some of flash’s included classes cough Tween cough… Along with this post is a class I created in order to simulate my own listeners. I will paste the code as well because it is rather short. I am also aware of an ASBroadcaster class (talked about http://www.kirupa.com/developer/actionscript/asbroadcaster2.htm) but just ended up fooling with the BroadcasterMX because that was used in these others as talked about above…
This is my test class:
import mx.transitions.BroadcasterMX;
class Kingdom {
static var __initBroadcaster = BroadcasterMX.initialize (Kingdom.prototype, true);
public var addListener:Function;
public var removeListener:Function;
public var broadcastMessage:Function;
private var _listeners:Array;
public function Kingdom() {
this._listeners = [];
this.addListener (this);
}
public function birthKing(name:String):Void {
var King:MovieClip = _root.createEmptyMovieClip(name, 0);
this.broadcastMessage("onKingBorn", this);
}
}
and here is its usage:
var myKingdom:Kingdom = new Kingdom();
myKingdom.birthKing("King_Richard");
myKingdom.onKingBorn = function() {
trace("A king was born!");
}
my problem is that it errors and says “No such property: onKingBorn”… Obviously I am doing something wrong, but my review of its usage in the Tween class proves unhelpful :(… any help?
here is the source for your convienence: http://iamvery.com/Random_Files/testClass.zip