How do you guys handle the following situation:

I have a class, let's say Dog that holds an instance of the class Leg.
Outside of Dog I have another class called Street that holds the dog.
Anyway, now I want street to find out whenever the dog's leg has
moved. The only way I can figure out how to do that is to send the
"move" event of the Leg class first to the holder of the Leg object
(in this case Dog) and then on to the holder of Dog, in this case
Street. I've ran into more complex cases when I've had to hand down
events through several classes...

Is there a common solution to this problem without the need to send
the event from one instance of a class to the next until it reaches
its final destination?

Below an example of what I mean...

class Street {
    function Street() {
        var myDog = new Dog();
        myDog.addEventListener("move", this);
    }
    function move() {
        trace("move event found!");
    }
}

class Dog {
    private var leg1:Leg;

    function Dog() {
        leg1 = new Leg();
        leg1.addEventListener("move", this);
    }
    function move() {
        dispatchEvent({type:"move"});
    }
}

class Leg {
    ....
    // this event is triggered through some other method of the Leg class.
    function move() {
        dispatchEvent({type:"move"});
    }
}

var blah = new Street();



Thanks,
Jan
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to