
Код AS3:
package
{
import flash.display.MovieClip;
public class Test extends MovieClip
{
public function Test()
{
dispatchEvent(new CustomEvent(CustomEvent.TROLOLO));
}
}
}

Код AS3:
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
public function Main()
{
addEventListener(CustomEvent.TROLOLO, onTroll)
addChild(new Test())
}
private function onTroll(e:CustomEvent):void{
removeChild(e.target as MovieClip);
trace ('!')
}
}
}

Код AS3:
package {
* *
* *import flash.events.Event;
*
* *public class CustomEvent extends Event {
* * *
public static const TROLOLO:String = 'trololo!';
* * *
* * * public var arg:*;
* * *
* * * public function CustomEvent(type:String, customArg:*=null,
bubbles:Boolean=true,
cancelable:Boolean=false) {
* * * * *
* * * * *super(type, bubbles, cancelable);
* * * * *
* * * * *this.arg = customArg;
* * * * *
* * * }
* * * * * *
* * * public override function clone():Event {
* * * * *return new CustomEvent(type, arg, bubbles, cancelable);
* * * }
* * *
* * * public override function toString():String {
* * * * *return formatToString("CustomEvent", "type", "arg",
* * * * * * * * * * * * * * * *"bubbles", "cancelable", "eventPhase");
* * * }
* *
* *}
*
}