Setting Event.target for using events in unit testing

1.4k views Asked by At

I want to override flash.display.Loader and to dispatch my own Event with a my own target.content

How can i override Event.target? "Property is read only"

Or use some other way to unit test the loading sequence

tnx Hed

2

There are 2 answers

1
weltraumpirat On BEST ANSWER

The target is always set to the object that dispatches the event. The proper way to unit test loading sequence is to mock the loaders - this unit test should test the logic used for loading sequentially, not the file system or network connection.

Wrap your loader into a custom class implementing a custom loader interface that extends IEventDispatcher. Use that interface to create a mock loader, and dispatch the event from the mock object.

0
Valentin Simonov On

You can't override target property. Though you can trick flash with special custom extended event but that will get ugly very soon.

What you need to do is to create a mock loader which contains a Loader instance, catches its event and dispatches a new one.