A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: objects talking to each other

Hybrid View

  1. #1
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973

    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

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    What would your example do as written there?
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973
    Quote 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

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  5. #5
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    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);

  6. #6
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Don't bother helping this guy, he'll just say you know nothing about it : http://www.actionscript.org/forums/s....php3?t=115341

  7. #7
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Quote Originally Posted by Fall_X
    Don't bother helping this guy, he'll just say you know nothing about it : http://www.actionscript.org/forums/s....php3?t=115341
    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. -

  8. #8
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    And even though I shouldn't bother, one more tip : why not just extend the EventDispatcher class? This probably does exactly what you want.

  9. #9
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Point taken.
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center