Copy link to clipboard
Copied
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];
}
}
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now