I want to know how to make class instances into listeners and broadcasters, from inside each class. Here is what I am trying specifically…
part of the Proj class… (projectiles, as a matter of fact)
private function listen():Void {
u.register(this);
**onUpdate** = function(){
step(); // a function I have which makes the projectile move (not shown)
}
}
where “u” is another class, the Updater class with this code…
class Updater {
// const. --- make this a broadcaster
public function Updater(){
AsBroadcaster.initialize(this);
}
// function to add a projectile as a listener
// (in this case, called *by *projectiles)
public function register( p:Proj ):Void {
addListener( p );
}
// update all projectiles listening to the updater
public function updateListeners():Void {
broadcastMessage("**onUpdate**");
}
}
Problem is, I get a bunch of errors:
[COLOR=darkred]There is no method with the name ‘addListener’.[/COLOR]
[COLOR=darkred]addListener( p );[/COLOR]
[COLOR=darkred]There is no method with the name ‘broadcastMessage’.[/COLOR]
[COLOR=darkred]broadcastMessage(“onUpdate”); [/COLOR]
[COLOR=darkred]There is no property with the name ‘onUpdate’.[/COLOR]
[COLOR=darkred]onUpdate = function(){[/COLOR]
Thanks in advance!
PS: What is the syntax for using AS2 code tags instead of just “[CODE|”?