Skip to main content
April 6, 2013
Answered

Can't stop sound playing!

  • April 6, 2013
  • 1 reply
  • 824 views

The problem is that I have a sound that plays inside a movieclip when the play head enters a frame (inside the movieclip), this is controlled by an event listener:

Multitouch.inputMode = MultitouchInputMode.GESTURE;

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeToGoToNextPreviousFrame_4);

function fl_SwipeToGoToNextPreviousFrame_4(event:TransformGestureEvent):void

{

    if(event.offsetX == 1)

    {

        // swiped right

        prevFrame();

    }

    else if(event.offsetX == -1)

    {

        // swiped left

        nextFrame();

    }

}

when the playhead in the maintime line, goes back to a frame before the one containing said movieclip,
swiping still causes this sound to play.


I am both unsure as to why this happens and home to stop it from happening

Any suggestions would be greatly appreciated

Thanks

This topic has been closed for replies.
Correct answer kglad

or make it so the soundclip is only played when the 'diary' movieclip is on the stage?


in the frame that contains your diary movieclip, use:

diary.addEventListener(Event.REMOVE_FROM_STAGE,removeF);

function removeF(e:Event):void{

stage.removeEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeToGoToNextPreviousFrame_4);

}

1 reply

kglad
Community Expert
Community Expert
April 6, 2013

what is occuring that you do not expect?

April 6, 2013

sorry I should have been clearer,

so I want the swipe gesture and the sound to play in the movieclip 'diary' on frame 5 (of the main timeline)

however when the playhead goes back to frame 3, which does not have the movieclip 'diary' in it, I do not want the sound to play and I do not need the swipe gesture.
Would I need to, for instance, remove the eventlistener before going back to frame 3?

Thanks

kglad
Community Expert
Community Expert
April 6, 2013

yes, when you no longer want the swipe gesture to no longer call the function shown in your first message, use:

stage.removeEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeToGoToNextPreviousFrame_4);