Ubb
Event bubbling (incident float mechanism)
OK, let me call it the event bubbling. Originally Ralf published in his blog on the As2.0 use event bubbling method. It's a creative idea.
Event bubbling was originally only used in AS3.0. In the event bubbling mechanism, the object that generated the event first receives the event. The event then propagates up according to the hierarchy of the object. So the simple use of the event bubbling in Flash is a lot simpler for the MC that handles nesting. The use of event bubbling is a good reinforcement of the continuity of incident handling.
Ralf's solution is to replace the dispatch method in its own way, the following is an example of Ralf, and you can modify it yourself:
public static initializebubbling (Dispatcher:movieclip) {
var parentdispatcher = dispatcher._parent; Add traversal Optionally, comments below
var olddispatchevent = dispatcher.dispatchevent;
Dispatcher.dispatchevent = function (evt) {
Olddispatchevent.call (Dispatcher, evt);
if (evt.bubbles) {
Parentdispatcher.dispatchevent (EVT);
}
}
}
More detailed articles, I think it is better to read the original text
At the same time, Peter Elst also wrote an example to use.
For example, when you do not use event bubbling, you need to make MC1.MC2 broadcast events in the following ways.
Mc1.mc2.addEventListener ("Someevent", Someeventhandler);
You can do this if you use event bubbling.
Mc1.addeventlistener ("Someevent", Someeventhandler);
Because of this event chain mechanism, you don't have to worry about where the time is coming from.
Import Mx.events.EventDispatcher;
Ralf Bokelberg ' s AS2.0 event bubbling Workaround
initializebubbling = function (dispatcher:movieclip) {
var parentdispatcher = dispatcher._parent;
var olddispatchevent = dispatcher.dispatchevent;
Dispatcher.dispatchevent = function (evt) {
Olddispatchevent.call (Dispatcher, evt);
if (evt.bubbles) {
Parentdispatcher.dispatchevent (EVT);
}
}
}
Create Empty MovieClips
var mc1:movieclip = Createemptymovieclip ("MC1", 1);
var mc2:movieclip = Mc1.createemptymovieclip ("MC2", 1);
Initialize Eventdispatcher
Eventdispatcher.initialize (MC1);
Eventdispatcher.initialize (MC1.MC2);
Initialize event bubbling
Initializebubbling (MC1.MC2);
Add event listeners to MovieClips
Mc1.mc2.addEventListener ("Customevent", function () {
Trace ("Customevent Captured by MC1.MC2");
});
Mc1.addeventlistener ("Customevent", function () {
Trace ("Customevent Captured by MC1");
});
Dispatch Event
Mc1.mc2.dispatchEvent ({type: "Customevent", bubbles:true});