-
Custom User Title
objects talking to each other
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:
code:
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
-
Senior Member
What would your example do as written there?
- The right of the People to create Flash movies shall not be infringed. -
-
Custom User Title
Originally Posted by cancerinform
What would your example do as written there?
I am trying to make an AsBroadcaster class in AS3, based on this one
code:
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
-
Senior Member
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.
- The right of the People to create Flash movies shall not be infringed. -
-
Code:
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
Code:
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);
-
Don't bother helping this guy, he'll just say you know nothing about it : http://www.actionscript.org/forums/s....php3?t=115341
-
Senior Member
Originally Posted by Fall_X
Please carry out any fights somewhere else but not on Flashkit. The original question is answered and therefore resolved.
- The right of the People to create Flash movies shall not be infringed. -
-
And even though I shouldn't bother, one more tip : why not just extend the EventDispatcher class? This probably does exactly what you want.
-
Last edited by cancerinform; 08-28-2006 at 11:17 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|