3 Replies Latest reply: Mar 7, 2012 1:39 AM by he11f1re RSS

    Event.ADDED_TO_STAGE is running twice...

    Amit Shakya Community Member


      public function main() {<<<< CLASS CONSTRUCTOR



      this.addEventListener(Event.ADDED_TO_STAGE,startapp)


      }






      private function startapp(event:Event):void{



      trace('start app') <<TRACING TWICE..



      //instructionscreen()



      closebtn.visible=false



      closebtn.alpha=0



      controls.alpha=0






      }
        • 1. Re: Event.ADDED_TO_STAGE is running twice...
          Sumit Agrawal FLash

          package

          {

              import flash.events.*;

              import flash.display.*

              public class Testing extends MovieClip

              {

           

                  public function Testing()

                  {

                      addEventListener(Event.ADDED_TO_STAGE,startapp)

             

                  }   

                 

                  private function startapp(event:Event):void

                  {

                      trace('start app')

                      //instructionscreen()

                      closebtn.visible=false

                      closebtn.alpha=0   

                      //controls.alpha=0

                  }

                 

              }

             

          }

           

          its running for once only

          • 2. Re: Event.ADDED_TO_STAGE is running twice...
            he11f1re

            Also remove the Event.ADDED_TO_STAGE listener in startapp function.

            • 3. Re: Event.ADDED_TO_STAGE is running twice...
              he11f1re Community Member

              You can do something like this :

               

              package

              {

                  import flash.events.Event;

                  import flash.display.*

                  public class Testing extends MovieClip

                  {

               

                      public function Testing()

                      {

                         if (stage) startapp();

                        else addEventListener(Event.ADDED_TO_STAGE,startapp);

               

                      }  

               

                      private function startapp(event:Event = null):void

                      {

                          removeEventListener(Event.ADDED_TO_STAGE,startapp);

                          trace('start app')

                          //instructionscreen()

                          closebtn.visible=false

                          closebtn.alpha=0  

                          //controls.alpha=0

                      }

               

                  }

               

              }