Skip to main content
Known Participant
January 9, 2013
Answered

Remove Frame Script

  • January 9, 2013
  • 1 reply
  • 1652 views

I have this function that is called by a frame. When I leave the frame it is still trying to run the createWater function.  How do I prevent it from doint that?

FRAME SCRIPT

createWater();

stop()l

FUNCTION

//Water Shimmmer;

function createWater()

{

          var bm:BitmapData = new BitmapData(water_MC.width,water_MC.height);

          var disp:DisplacementMapFilter = new DisplacementMapFilter(bm,new Point(0,0),1,2,10,60)

          var pt1:Point = new Point(0,0);

          var pt2:Point = new Point(0,0);

          var perlinOffset:Array = [pt1,pt2];

          stage.addEventListener(Event.ENTER_FRAME, onFrame);

          function onFrame(evt:Event):void

          {

                    perlinOffset[0].x +=  1;

                    perlinOffset[1].y +=  0.1;

                    bm.perlinNoise(45,9,2,50,true,false, 7,true,perlinOffset);

                    water_MC.filters = [disp];

          }

}

This topic has been closed for replies.
Correct answer Ned Murphy

You shouldn't be nesting the onFrame function like you do.  Pull it out on its own.  Aside from that, if you want to stop that function you need to remove the ENTER_FRAME listener at whatever point in the code where you make the move to another frame.

      stage.removeEventListener(Event.ENTER_FRAME, onFrame);

That might be all you need to do since that appears to be the only things that would keep working after you leave the frame.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 9, 2013

You shouldn't be nesting the onFrame function like you do.  Pull it out on its own.  Aside from that, if you want to stop that function you need to remove the ENTER_FRAME listener at whatever point in the code where you make the move to another frame.

      stage.removeEventListener(Event.ENTER_FRAME, onFrame);

That might be all you need to do since that appears to be the only things that would keep working after you leave the frame.