all groups > flash actionscript > april 2004 >
You're in the

flash actionscript

group:

onMouseDown Listener for just one clip?


onMouseDown Listener for just one clip? rwmorey71
4/22/2004 9:31:24 PM
flash actionscript:
Hi,

I have added an onMouseDown listener inside a movie clip:

downListener = new Object();
downListener.onMouseDown = function () {

// code is here..

};

Mouse.addListener(downListener);


The problem is that the code inside this listener executes whenever I click
the mouse button. I have tried making this listen unique to this clip this way:

this.Mouse.addListener(downListener);

and

instDragClip.Mouse.addListener(downListener);

but both make the code not execute at all (anywhere)..

There does not seem to be an

on(mouseDown) {


}

that I can put inside a clip.. Can someone help me out?

Thanks,

Rich



Re: onMouseDown Listener for just one clip? mandingo
4/22/2004 11:39:07 PM
Well, all I can say is no real surprises here...

The code executes because you have told it to execute.

If you only want to have the code execute in specific circumstances, then put
those conditions inside your listener...

downListener = new Object();
downListener.onMouseDown = function () {

if(myTargetForMouseClickMovieClip.hitTest(_xmouse,_ymouse){

// then execute my code in herecode is here..

}
};

Mouse.addListener(downListener);


Is that what you meant?

hope this helps
cheers,
Re: onMouseDown Listener for just one clip? krl
5/27/2004 7:36:33 PM
I am having a same sort of problem.
I want a function that toggles the visibility on and off of a movie clip by
clicking on another movie clip, specifically I am using a text field converted
to a movie clip. Any ideas for this? Thanks.
krl
Re: onMouseDown Listener for just one clip? parker.p NO[at]SPAM ucles.org.uk
6/1/2004 11:10:00 AM
The way suggested by mandingo will work in fact it can be simplified
to:

function onMouseDown() {
if(myTargetForMouseClickMovieClip.hitTest(_xmouse,_ymouse){
// then execute my code in herecode is here..
}
};

I'm not convinced that using event handlers is ideal for this
detecting mouse clicks as every single clip will be checked for every
single click. The other way to do it is as follows:

myTargetForMouseClickMovieClip.onRelease = function(){
// then execute my code in herecode is here..;
}

Not sure if it is desirable for your application but this also means
the mouse pointer turns to a hand when hovering over your movieclip.

You can also put the actionscript inside the actual movieclip using
'this' instead of the movieclip name but this is generally frowned
upon as it makes it hard to find all the actionscript in a project.

Cheers,

Re: onMouseDown Listener for just one clip? mandingo
6/1/2004 11:14:32 PM
Hey krl,

I don't know why you thought that this thread was linked to your issue... but
your answer is quite simple...

on your button instance that is going to do the toggle :

on(release){
myTextField._visible = !myTextField._visible;
}

that will toggle it on and off.

hope that helps,
cheers,
Re: onMouseDown Listener for just one clip? krl
6/2/2004 12:41:44 AM
mandingo,
that's beautiful! thanks for the help.
God bless.
Re: onMouseDown Listener for just one clip? mandingo
6/2/2004 12:58:06 AM
Glad to
AddThis Social Bookmark Button