crooksy88
asked on
Remove Listener in Flash AS2
Hi Experts,
Within the code attached (playtrick function) I am adding a listener to the mouse which resets the playback head on a custom flv skin I have created.
If the function is re-run, the removeit function is called which should remove all instances of any movieclips or listeners. So we can, in effect, start over from scratch.
This all works fine except for my problem is that the mouse listener doesn't seem to be being cleared or deleted, so if I play the function a second time, a second instance of the mouse listener is created and when I press the _root.flvskin.my_seekBar I get a double jump in the flv.
So, to summarize, what I need to do is to get the removeit function to remove or delete the mouse listener.
Can anyone see what I am doing wrong???
Thanks,
Mark
Within the code attached (playtrick function) I am adding a listener to the mouse which resets the playback head on a custom flv skin I have created.
If the function is re-run, the removeit function is called which should remove all instances of any movieclips or listeners. So we can, in effect, start over from scratch.
This all works fine except for my problem is that the mouse listener doesn't seem to be being cleared or deleted, so if I play the function a second time, a second instance of the mouse listener is created and when I press the _root.flvskin.my_seekBar I get a double jump in the flv.
So, to summarize, what I need to do is to get the removeit function to remove or delete the mouse listener.
Can anyone see what I am doing wrong???
Thanks,
Mark
//playtrick
function playtrick(whichflv) {
// run the removeit function to try to remove all listeners and movieclips
removeit();
this.attachMovie("FLVPlayback", "my_FLVPlybk", 30, {width:640, height:360, _x:20, _y:140});
this.attachMovie("flvskin", "flvskin", 32, {_x:20, _y:500});
my_FLVPlybk.seekBar = flvskin.my_seekBar;
my_FLVPlybk.contentPath = "test.flv";
var myListener = new Object();
myListener.onMouseDown = function() {
if (_root.flvskin.my_seekBar.hitTest(_root._xmouse, _root._ymouse, true)) {
my_FLVPlybk.playheadPercentage = _root.flvskin.my_seekBar._xmouse;
my_FLVPlybk.play();
}
};
Mouse.addListener(myListener);
//removeit
function removeit() {
Mouse.removeListener(myListener);
delete "_root.flvskin.myListener";
removeMovieClip("_root.my_FLVPlybk");
removeMovieClip("_root.flvskin");
}
ASKER
Thanks for your reply but that doesn't seem to work.
The errors I get seem to suggest that you can't use Mouse.addEventListener.
???
The errors I get seem to suggest that you can't use Mouse.addEventListener.
???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fantastic. That's sorted it.
Many thanks for your help!
Many thanks for your help!
Open in new window