onMouseUp is a global function

If you have the following:

class MyButton extends MovieClip {
 function onMouseUp() {
  trace("onMouseUp");
 }
}

And put 100 instances on stage.
Each time you click and release *anywhere* in you application, you'll get 100 
traces.

If you want to use mouse events and detect when a certain instance has been 
clicked upon, use hitTest

class MyButton extends MovieClip {
 function onMouseUp() {
  trace("onMouseUp");
  if (this.hitTest(_root._xmouse, _root._ymouse)) {
   trace(this+" says: ouch, you've hit me!");
  }
 }
}

You'll only see the second trace if the mouse is over one of the instances, and 
for that instance only.

regards,
Muzak

----- Original Message ----- 
From: "Daniel Forslund|Lists" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
Sent: Friday, October 20, 2006 2:39 PM
Subject: [Flashcoders] onMouseup bug?


> Hi all!
>
> I've stumbled upon something quite weird, and have searched for an  
> explanation without any success.
> Consider the following Movieclip hiearchy:
> Contentclip (with a few images and text fields dynamically attached) -
> > buttonclip
>
> I have created a class which when instanced will:
> - attach a new instance of contentclip to level0
> - attach onRollOver,onRollOut,onMouseUp functions to the child  buttonclip
>
> When the movie runs, a rollover/rollout of one of the buttonclips  will alert 
> ONLY the object (class instance) that created it.
> However, when clicking on one of the buttonclips and capturing the  event 
> with onMouseUp, ALL the objects linked to contentclips 
> will be  called. Ie, if I have a function that create 4 objects that in turn  
> each create one contentclip, one click on one button 
> will result in 4  separate calls to each one of the 4 instance objects.
>
> Now for the weird part which makes me strongly suspect it's a bug  rather 
> than poor programming on my part:
> If I swap the onMouseUp event for an onPress event, the problem goes  away. I 
> get one call to the "parent" object which attached 
> the  onPress function - as I would have expected all along.
>
> I apologize for the poor description, I hope it makes sense and that  someone 
> can explain what's going on to me. :-)
> Many thanks in advance!
> Dan
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
> 


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to