1 Reply Latest reply on Jun 18, 2011 6:18 AM by Ned Murphy

    Error adding child on interval...

    McbainGames11 Level 2

      Hey,

       

      Im trying to add an extra movieclip to stage with this code, i want an extra movieclip added every 10 seconds..

       

      addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

       

      function fl_EnterFrameHandler(event:Event):void
      {
          addChild(movieclip);
         
      }

       

      This error shows up:
      setInterval(fl_EnterFrameHandler,10000);
      ArgumentError: Error #1063: Argument count mismatch on Untitled_fla::MainTimeline/fl_EnterFrameHandler(). Expected 1, got 0.

       

       

      Please help me someone

        • 1. Re: Error adding child on interval...
          Ned Murphy Adobe Community Professional & MVP

          There are a few things you do not want with the code you show.

           

          1) You do not want the ENTER_FRAME event listener.  That will call the fl_EnterFrameHandler function at the frame rate of your file.

           

          2) Using addChild() is not how you add new objects, it is only how you add objects to the display list.  You need to create the new object instances, such as in...

           

              var newObj:MC = new MC(); // where MC is whatever class name you assign to the MovieClip

           

          and then you can use addChild(newObj) to add the object to the display list.

           

          The way you have it now, it will simply keep moving the same object to the top of the display.

           

          3) The error you are getting is because your function is expecting an argument to be passed to it, which the ENTER_FRAME listener provides, but the setInterval does not. If you get rid of the ENTER_FRAME listener, then you just need to change the function definition line to be...

           

              function fl_EnterFrameHandler():void

           

          Just for future consideration, if there is an instance where you need to call a function that a listener also calls, but you do not have an Event argument to pass to the function, then you can accomodate that scenario by nulling the argument in the function definition line...

           

              function fl_EnterFrameHandler(event:Event=null):void