So, I want to configure events so that I can transmit data without creating a memory closure / leak. This, as I understand it:
package com.events { import flash.events.Event; public class CustomEvent extends Event { public static const REMOVED_FROM_STAGE:String = "removedFromStage"; public var data:*; public function CustomEvent(type:String, customData:*=null, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); this.data = customData; } public override function clone():Event { return new CustomEvent(type, data, bubbles, cancelable); } public override function toString():String { return formatToString("CustomEvent", "type", "data", "bubbles", "cancelable", "eventPhase"); } } }
This leads me to the following behavior:
function testme(e:Event) { trace(e); } test_mc.addEventListener(CustomEvent.REMOVED_FROM_STAGE, testme); test_mc.dispatchEvent(new CustomEvent(CustomEvent.REMOVED_FROM_STAGE, 42)); //Traces [CustomEvent type="removedFromStage" data=42 bubbles=false cancelable=false eventPhase=2] removeChild(test_mc); //Traces [Event type="removedFromStage" bubbles=false cancelable=false eventPhase=2]
My goal is to get the user data that I want to pass in order to get past the flash fire events, not just the one that I am running. For example, what if I wanted to pass a movie clip along with the loader.COMPLETE event to put the resulting bitmap in?
events actionscript-3 listener observer-pattern
Joren
source share