I have been converting most of my AS2 codes to AS3, one issue that I have encountered is “buttonMode” property for MovieClip.
If you have included frames labeled _up, _over, and _down, Flash Player provides automatic state changes, it is the same for AS2/AS3. But if you have a MovieClip within a MovieClip that has been set “buttonMode” to true and use MouseEvents like MOUSE_OVER or MOUSE_UP etc…, you will find that when you click the button (MovieClip), the child mc will receive the mouse event instead, not the button itself for AS3… (AS2 doesn’t behave this way) so you will need “event.target.parent” to get the button itself.
To avoid above problem, you will need to set “mouseChildren” property (inherited from the DisplayObjectContainer class) to false instead, eg:
mc.buttonMode = true;
mc.mouseChildren = false;
mc.addEventListener(MouseEvent.MOUSE_UP, function(event:MouseEvent) {
trace("The button is: "+event.target);
});
Also the up/over/down button state will not work if “mouseChildren†is not set to false.
4 users commented in " AS3 buttonMode issues "
Follow-up comment rss or Leave a TrackbackYou could also just use event.currentTarget, and that returns the clip that is registered for the event (the listener) and not the child clip.
Thanks, but I also meant that the up/over/down state will not work if “mouseChildren” is not set to false… (will update the article)
I think also it’s better to use mouseChildren set to false since this will stop events propagating all the way down…
You are a king among men. That mc.mouseChildren = false; trick was what I was needing to find! Brilliant - saved me hours
Leave A Reply