Click to See Complete Forum and Search --> : objects talking to each other
Incrue
08-28-2006, 07:39 AM
I want objA to fire some function in objB
The name of object to fire and the name of the function must be inside variables in objA
The problem is:in AS2 this works, but in AS3,it dont:
var objA = new Object();
var objB = new Object();
objB.doThis = function(){
trace("objB doing this");
}
objA.obName = "objB";
objA.funcName = "doThis";
objA[obName][funcName]();
So, what i do?
Thanks in advance
cancerinform
08-28-2006, 08:56 AM
What would your example do as written there?
Fall_X
08-28-2006, 11:11 AM
var objA = new Object();
var objB = new Object();
objB.doThis = function(){
trace("objB doing this");
}
objA.obName = "objB";
objA.funcName = "doThis";
this[objA.obName][objA.funcName]();
or
var objA = new Object();
var objB = new Object();
objB.doThis = function(p1:String,p2:String){
trace("parameter 1 : "+p1);
trace("parameter 2 : "+p2);
}
objA.obName = "objB";
objA.funcName = "doThis";
objA.parameters = ["value 1","value 2"];
this[objA.obName][objA.funcName].apply(this[objA.obName],objA.parameters);
Incrue
08-28-2006, 11:14 AM
What would your example do as written there?
I am trying to make an AsBroadcaster class in AS3, based on this one
AsBroadcaster = new Object();
AsBroadcaster.addListener = function(listener){
this.removeListener(listener);
this._listeners.push(listener);
return true;
}
AsBroadcaster.removeListener = function(listener){
var i = this._listeners.length;
while(--i >= 0){
if(this._listeners[i] == listener){
this._listeners.splice(i,1);
return true;
}
}
return false;
}
AsBroadcaster.broadcastMessage = function(theEvent){
var i = this._listeners.length;
while(--i >= 0){
this._listeners[i][theEvent]();
}
}
AsBroadcaster.initialize = function(obj){
obj.addListener = this.addListener;
obj.removeListener = this.removeListener;
obj.broadcastMessage = this.broadcastMessage;
obj._listeners = [];
}
It wasnt working, i think the problem is that this line
this._listeners[i][theEvent]();
Is not making the listener object do the [theEvent]function, i dont know why
cancerinform
08-28-2006, 11:20 AM
Your original example didn't work in AS2 either. That is why I was wondering, but Fall_X example is working in AS3 as well.
Fall_X
08-28-2006, 11:25 AM
Don't bother helping this guy, he'll just say you know nothing about it : http://www.actionscript.org/forums/showthread.php3?t=115341 :rolleyes:
Fall_X
08-28-2006, 11:34 AM
And even though I shouldn't bother, one more tip : why not just extend the EventDispatcher class? This probably does exactly what you want.
cancerinform
08-28-2006, 11:54 AM
Don't bother helping this guy, he'll just say you know nothing about it : http://www.actionscript.org/forums/showthread.php3?t=115341 :rolleyes:
Please carry out any fights somewhere else but not on Flashkit. The original question is answered and therefore resolved.
Fall_X
08-28-2006, 11:59 AM
Point taken.
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.