# Nested Event Listeners with Custom Events - Time Sensitive

**URL:** <https://forum.kirupa.com/t/nested-event-listeners-with-custom-events-time-sensitive/289428>\
**Category:** flash\
**Created:** [May 30, 2009, 6:00am UTC](https://forum.kirupa.com/t/nested-event-listeners-with-custom-events-time-sensitive/289428 "2009-05-30T06:00:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prstudio](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@prstudio](https://forum.kirupa.com/u/prstudio)\
**Post date:** [May 30, 2009, 6:00am UTC](https://forum.kirupa.com/t/nested-event-listeners-with-custom-events-time-sensitive/289428/1 "2009-05-30T06:00:56Z")

</div>

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

Custom Event Class:

```auto
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:

```auto
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:

```auto
urlLoader.addEventListener(Event.COMPLETE, onSwfLoaded);

```

But stops on the second addEventListener.

If I just apply the custom event to the following…

```auto
_loader.addEventListener(Event.COMPLETE, onLoaderInit);

```

VERSUS

```auto
_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 🙂
