 <p>Your event:</p> <pre><code>package { import flash.events.Event; public class ProgramEvent extends Event { public static const FINISH:String = "Finished" ; public function ProgramEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); } public override function clone():Event { return new ProgramEvent(type, bubbles, cancelable); } public override function toString():String { return formatToString("ProgramEvent", "type", "bubbles", "cancelable", "eventPhase"); } } } </code></pre> <p>RunMain:</p> <pre><code>package { import flash.display.Sprite; import flash.events.Event; public class RunMain extends Sprite { public function RunMain():void { addEventListener(Event.ENTER_FRAME, loop); } private function loop(event:Event){ removeEventListener(Event.ENTER_FRAME, loop); dispatchEvent(new ProgramEvent(ProgramEvent.FINISH)); } } } </code></pre> <p>And Main:</p> <pre><code>public function Main() { startProgram() ; init(); otherMethods(); } public function onProgramFinish(event:ProgramEvent) { runMain.removeEventListener(ProgramEvent.FINISH, onProgramFinish) ; removeChild(runMain); runMain = null; startProgram() ; } public function startProgram(){ runMain = new RunMain() ; runMain.addEventListener(ProgramEvent.FINISH, onProgramFinish); addChild(runMain); } </code></pre>