Link to home
Start Free TrialLog in
Avatar of crooksy88
crooksy88Flag for United Kingdom of Great Britain and Northern Ireland

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
//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");
	
}

Open in new window

Avatar of asaivan
asaivan
Flag of United States of America image

I think the problem is that myListener.onMouseDown is already listening for the event.  You should try something along these lines, although I haven't tested it.  I'm not sure about the "down" part, it may be some other string.



function mouseDownHandler() {
        if (_root.flvskin.my_seekBar.hitTest(_root._xmouse, _root._ymouse, true)) {
                my_FLVPlybk.playheadPercentage = _root.flvskin.my_seekBar._xmouse;
                                my_FLVPlybk.play();
        }
};
Mouse.addEventListener("down",mouseDownHandler);
 
 
//removeit
function removeit() {
        
        Mouse.removeEventListener("down", mouseDownHandler);
        delete "_root.flvskin.myListener";
        removeMovieClip("_root.my_FLVPlybk");
        removeMovieClip("_root.flvskin");
        
}

Open in new window

Avatar of crooksy88

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.

???
ASKER CERTIFIED SOLUTION
Avatar of asaivan
asaivan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fantastic. That's sorted it.

Many thanks for your help!