Skip to main content
asrolr82301770
Participating Frequently
May 27, 2018
Answered

how to remove event listener

  • May 27, 2018
  • 1 reply
  • 3689 views

stop();

stage.addEventListener(Event.ENTER_FRAME,EntFrame);

function EntFrame(e:Event):void

{

//puzzle1

puzzle1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_5);

function fl_ClickToDrag_5(event:MouseEvent):void

{

puzzle1.startDrag();

}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_5);

function fl_ReleaseToDrop_5(event:MouseEvent):void

{

puzzle1.stopDrag();

}

if (target1_mc.hitTestObject(puzzle1.tar1_mc))

{

puzzle1.x = 302.95;

puzzle1.y = 221.85;

}

//puzzle2

puzzle2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_6);

function fl_ClickToDrag_6(event:MouseEvent):void

{

puzzle2.startDrag();

}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_6);

function fl_ReleaseToDrop_6(event:MouseEvent):void

{

puzzle2.stopDrag();

}

if (target2_mc.hitTestObject(puzzle2.tar2_mc))

{

puzzle2.x = 447.65;

puzzle2.y = 219.15;

}

//puzzle3

puzzle3.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_7);

function fl_ClickToDrag_7(event:MouseEvent):void

{

puzzle3.startDrag();

}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_7);

function fl_ReleaseToDrop_7(event:MouseEvent):void

{

puzzle3.stopDrag();

}

if (target3_mc.hitTestObject(puzzle3.tar3_mc))

{

puzzle3.x = 314.25;

puzzle3.y = 298;

}

//puzzle4

puzzle4.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_8);

function fl_ClickToDrag_8(event:MouseEvent):void

{

puzzle4.startDrag();

}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_8);

function fl_ReleaseToDrop_8(event:MouseEvent):void

{

puzzle4.stopDrag();

}

if (target4_mc.hitTestObject(puzzle4.tar4_mc))

{

puzzle4.x = 460.8;

puzzle4.y = 297.9;

}

}

/* Click to Go to Frame and Stop

Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.

Can be used on the main timeline or on movie clip timelines.

Instructions:

1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.

*/

movieClip_3.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);

function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void

{

gotoAndStop(2);

}

****** I Had 5 type of puzzle and each puzzle is located in among 5 frame . When i play the swf , the error #1009 occur. I realize that i needed to remove the event listener .

****** For my next frame

stage.addEventListener(Event.ENTER_FRAME,EntFrame);

function EntFrame(e:Event):void

if i put the same code it will become duplicate .

should i just put like this ?

stage.addEventListener(Event.ENTER_FRAME,EntFrame2);

function EntFrame2(e:Event):void

This topic has been closed for replies.
Correct answer kglad

Instructions:

1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.

*/

movieClip_3.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);

function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void

{

gotoAndStop(2);

}

put the code here ?


yes, that looks like a good spot:

movieClip_3.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);

function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void

{

stage.removeEventListener(Event.ENTER_FRAME,EntFrame)

gotoAndStop(2);

}

1 reply

kglad
Community Expert
Community Expert
May 27, 2018

use

stage.removeEventListener(Event.ENTER_FRAME,EntFrame)

to remove an event listener.

[moved from Adobe Creative Cloud to ActionScript 3]

asrolr82301770
Participating Frequently
May 27, 2018

Where do i need to put that ?

kglad
Community Expert
Community Expert
May 27, 2018

wherever and whenever you want to remove the listener.

if that's before changing frame, add it to the code that changes the frame.