Nested Event Listeners with Custom Events - Time Sensitive

Hey everyone - need some help -
Here’s a hodge-podge of information:

Custom Event Class:

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");
        }
    }
}

Using the following:

var urlLoader:URLLoader = new URLLoader();
			urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
			urlLoader.addEventListener(Event.COMPLETE, onSwfLoaded);
			urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
			urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
onSecurityError);
			try {
				urlLoader.load(new URLRequest(txtPath.text));
			} catch (e:Error) {
				resetBrowseControls();
				txtError.text = "Error:
" + e.toString();
				urlLoader.removeEventListener(Event.COMPLETE, onSwfLoaded);
				urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIoError);
				urlLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,
onSecurityError);
			}

		}

		private function onSwfLoaded(e:Event):void {
			var urlLoader:URLLoader = URLLoader(e.currentTarget);
			urlLoader.removeEventListener(Event.COMPLETE, onSwfLoaded);
			urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIoError);
			urlLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,
onSecurityError);

			_bytes= ByteArray(URLLoader(e.currentTarget).data);

			_loader = new Loader();
			var loaderContext:LoaderContext = new LoaderContext();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onLoaderInit);
			_loader.loadBytes(_bytes, loaderContext);
		}

		private function onLoaderInit(e:Event):void {
			resetBrowseControls();
			populateList(_bytes);
		}

I made a custom loader to replace the urlLoader and even tried a
replacement for the _loader using the same custom event.

Works great for the first addEventListener:

urlLoader.addEventListener(Event.COMPLETE, onSwfLoaded);

But stops on the second addEventListener.

If I just apply the custom event to the following…

_loader.addEventListener(Event.COMPLETE, onLoaderInit);

VERSUS

_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderInit);

it works just fine.

As soon as I use it on the contentLoaderInfo line, it throws that type
error
cannot convert CustomEvent to Event error.

I also double checked that my custom event listener was overriding clone()
properly and it looks like it does.

Any ideas as to why it’s different?

Thanks :slight_smile: