MovieClip looses handCursor when TextField added to it,why? - actionscript-3

I am making an application where I need to create all controls by code so no flash ide is used. I am also creating a btn:MovieClip which will be a button and I add event listeners to it and also useHadCursor and ButtonMode are true. I also add a static text field with text in it "Save" so this would be save button.
But when I add the textfield the movieclip stops to show the hand cursor. What am I doing wrong?

I am assuming the problem is caused by the textfield. Having said that if your movieclip has only textfield in it try setting mouseChildren to false. By doing so you can effectively prevent the mouse from being enabled for all instances within any display object container.But remember that it will apply to all children.
You can disable mouse interaction by setting their mouseEnabled property to false for the particular textfield you want. However, if you only want to disable certain mouse events for a collection of objects within a container, you'll need to take an alternate approach. In this situation, you'll use an event listener in the target parent instance listening for the event to be disabled and have that listener stop propagation of that event. This prevents the listeners working for objects within that container from being called.

I have had problems with TextFields and cursors in the past. It seems that TextFields have some special characteristics that give it priority over mouse events. This is important so that when you mouse over a TextField, you can get the text entry cursor for input TextFields.
As far as the solution goes - try setting the mouseEnabled and selectable properties to false on the TextField.

theTextField.selectable = false; should be enough. Setting mouseEnabled or mouseChildren to false can cause undesirable consequences in certain situations.
PS: Unless one of its parents has useHandCursor set to true. Then you WILL need mouseChildren on the parent set to false, or mouseEnabled set to false on the TextField.

Related

AS3: Managing two TextInputs

I am pretty new to AS3 and I'd like to learn from the more experienced ones how to do it right. The problem I have is: having two text inputs, having the ability to change the focus from one to another and the most important one, make the input lose focus on click outside.
The problems I faced here are:
When I click outside text inputs, it does not loses focus
If I focus in a text input, minimize browser and come back, it auto refocuses the last element.
How do you see this process implemented and what could I do to solve the problems I face?
To drop focus on your textfields, set a mouse event on the stage:
stage.addEventListener( MouseEvent.CLICK, onDropFocus );
function onDropFocus( evt:MouseEvent ):void
{
Stage.focus = null;
}
To reset the proper textfield focus, store a reference to it when you focus in on your textfield, then try listening for Event.DEACTIVATE on your stage, which is triggered when the flash movie loses focus. Then you can refocus to the intended textfield before leaving the page, (like when minimizing).

AS3 cancel event

Hey so I have an MC with multiple buttons in it, I can drag the container MC, when I release the MC I want to cancel any MouseEvent.CLICK listeners that may have fired during. mouseEnabled and mouseChildren is not an option for my current problem, thanks.
Can you use an option to intercept events of container from travelling to child while dragging?
Add listener to container, and stop propagation on those events, using capture phase.

Multiple mouse event as3

I got a MovieClip that is listening to mouse over and out events.
Inside this movie clip I want to show a button when mouse over.
The problem is that movie clip gets the mouse out event when moving to the button area.
I want him to get mouse out event only when living his rect area.
I found one solution: to make mouse position calculation and compare them to my movieClip position to detect if I should handle or ignore the event.
But is there more simple, more Adobe solution?
Edit: The inner button need to receive mouse events as well
set mouseChildren = false for your MovieClip or use ROLL_OVER and ROLL_OUT, here's a great article on the subject
ROLL_OVER and ROLL_OUT events should work (use them instead of MOUSE_OVER and MOUSE_OUT).
Does the inner button need to receive MouseEvents as well? If not, just set it's
button.mouseEnabled = false;
or you can set the parent movie clip's
movieclip.mouseChildren = false;

AS3 deactivate (MovieClip) Buttons

I want to temporarily deactivate some movieclips that are used as buttons. Currently I don't keep track of the EventListeners that got added to these buttons. I want to be able to deactivate and reactivate them later.
myMc.mouseEnabled=false;
works, but then they are still select- and clickable using the TAB key on the keyboard.
how to prevent that?
MovieClips have a property called enabled which prevents the MovieClip featuring in the tab order. Use this is conjunction with mouseEnabled to completely disable a MovieClip.
In AS3 MovieClips no longer appear or behave as buttons even when they have listeners although they would work just fine when clicked or rolled over with mouse, you have to specifically enable the button mode for MovieClips to make them change cursor to hand:
buttonMC.buttonMode = true;
buttonMC.useHandCursor = true;
To disable the button completely, remove the listener for each event you want it to stop working and also disable the button mode for the MovieClip:
buttonMC.removeEventListener(MouseEvent.CLICK, onClickHandler);
buttonMC.removeEventListener(MouseEvent.MOUSE_DOWN, onPressHandler);
buttonMC.removeEventListener(MouseEvent.MOUSE_UP, onReleaseHandler);
buttonClip.buttonMode = false;
source: http://www.parorrey.com/blog/flash-development/how-to-enabledisable-movieclips-as-buttons-in-flash-with-actionscript-3-0/
Or a quick way would be to hide the movieclips when not required
myMc.visible = false;

as3 mouseEnabled still a problem for me

A couple years in now, there's still something about mouseEnabled I'm not getting. I have a Sprite (for example here "Sky", that contains many objects, one of them is a Cloud, which I do not want to receive Mouse Events. I overlay this Sky on some other display objects. I want the cloud to be visible, but not to block mouse events. If you see a tree through the clouds you should be able to click on the tree.
In the Sky class:
mouseEnabled = false;
cloud.mouseEnabled = false;
cloud.mouseChildren = false;
Even with this configuration, when the cloud is over the tree I can't click on the tree because the cloud blocks it. Why???
Even though Sky has mouseEnabled/mouseChildren set to false... it's still an object, it still takes up space, and therefore still acts as a hit area for any PARENT containers that don't have mouseEnabled/mouseChildren set to false.
Therefore, I suspect your Sky object is not in the same parent container as your Tree object. Your Sky object probably has its own parent container object, which is the culprit intercepting the events.
To elaborate: Any object that contains ANYTHING will have a hit area and will intercept mouse clicks, even though all the individual things it contains (shapes, child objects, etc.) may have mouseEnabled/mouseChildren set to false.
So even though your Sky object has mouseEnabled set to false, your Sky (and it's children) still take up space, and therefore still give Sky's parent container a hit area to intercept mouse events.
Your solution, therefore, is to make sure all the parent containers of Sky have thier mouseEnabled property set to false, at least up to (but not including) the first common ancestor container of the Tree and Sky objects.
Also, by setting mouseEnabled=false and leaving mouseChildren=true, you can have a container where only select children with mouseEnabled=true receive click events :)
You say there's "many objects" in there? More than likely something else is blocking it. I recommend adding a listener to the stage and then you can see which object is receiving clicks:
import flash.utils.getQualifiedClassName;
stage.addEventListener(MouseEvent.CLICK, onClick);
private function onClick(event:MouseEvent):void
{
trace(event.target.name, getQualifiedClassName(event.target));
}
Post more code and we can probably help more.