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

LVL 13
crooksy88Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

asaivanCommented:
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

0
crooksy88Author Commented:
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.

???
0
asaivanCommented:
Oh, I see, it looks like a scope problem.  You're declaring your mouse listener inside the playtrick block.  You can't access it because it's a local object with a local scope.

In order to access it, you have to take it out of the playtrick block.  Try declaring it first, then assigning a value.  e.g.


var myListener = new Object(); 
 
function playtrick()
{
   myListener.onMouseDown...
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crooksy88Author Commented:
Fantastic. That's sorted it.

Many thanks for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.