Skip to main content
Participant
August 21, 2012
Question

adding and removing a movie clip on enter and exit frame

  • August 21, 2012
  • 1 reply
  • 2231 views

addEventListener(Event.ENTER_FRAME,addShip_move_mc);

addEventListener(Event.EXIT_FRAME,removeShip_move_mc);

function addShip_move_mc(e:Event):void

{

          //adds main menu to the screen

          var testaccel_ship_01:accel_ship_01 = new accel_ship_01();

          testaccel_ship_01.y = 195;

          testaccel_ship_01.x = 22;

          addChild(testaccel_ship_01);

          visible = true;

          trace("open ship movie");

}

function removeShip_move_mc(e:Event):void

{

          if (visible = true);

          {

                    removeChild(testaccel_ship_01);

                    trace("close ship movie");

          }

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
August 21, 2012

You might not understand what you are asking for as far as using the ENTER_FRAME/EXIT_FRAME event listeners.  What they will do is process continually at the fps rate of your file.

Also, in declaring the variable testaccel_ship_01 inside the function, it is limited to within the scope of that function, so your remove function cannot target it using that variable name.

If you explain the intentions of what you are trying to do, an alternative approach can probably be offered.

Participant
August 22, 2012

I am creating an Air App which has different content on different frames, on the frame in question there is a movie clip with a game controlled by the accelerometer, this all works fine until you try and navigate away from this frame and everything starts to respond slowly as if the accelerometer movie clip is still running in the background so I am trying to get this movie clip to load on entering the frame and remove when leaving the frame to try and solve the problem.

Ned Murphy
Legend
August 22, 2012

Chances are the enterframe/exitframe code is still continuously churning away creating and removing things. 

If you just place the code inside the addShip_move_mc by itself in that frame, that is all you need to have it execute (once) when you enter the frame.

          var testaccel_ship_01:accel_ship_01 = new accel_ship_01();

          testaccel_ship_01.y = 195;

          testaccel_ship_01.x = 22;

          addChild(testaccel_ship_01);

          visible = true;

As far as removing it when you leave the frame, what control do you have that causes it to change frames?  That would be one place to include the commands to remove it.