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;
Related
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).
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;
I really don't know how to explain this problem. I'm really stumped as to what is causing it.
Here is the code:
var abutton:AButton = new AButton; //Where AButton is a button defined in my library
addChildAt(abutton, numChildren);
abutton.addEventListener(MouseEvent.CLICK, attack);
It doesn't want to work when certain movie clips are underneath it, but I don't want to make it more complicated by switching to another screen. Is it possible to make the button work with movieclips underneath?
What do you mean by "certain movieclips"? What do you mean by not working? The CLICK event isn't firing? Normally if a click isn't working on a button, it means that something else it trapping the mouse click above your button. This can be another Sprite, MovieClip or TextField.
Add a click listener to the stage, and have it print out target and currentTarget. Then, when you button doesn't work, the stage listener will still fire and you'll be able to see the object that's blocking your button.
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.
I want to create a dialog or alert box, where a DisplayObject would take and force the focus, until an okay button or something releases the lock. thanks.
The easy way to do this is to make your "dialog" as big as the stage, with a whacking great transparent area around the dialog itself.
The transparent area can listen for any mouse clicks, and just swallow them (which will prevent them being picked up by stuff further back in the display list).
To show the alert, just stick it on top of everything else, When the user closes it, take it away again.
If you are using flex and actionscript, simply use a SkinnablePopUpContainer
var alt:CustomPopUp = new CustomPopUp();
alt.open(this,true) //the second variable is for modal, which will disable view
this.enabled = false; //this will grey out the parent view and provide visual focus to your popup.
To do this, you will need to disable access to all objects under your 'alert' DisplayObject. There are multiple ways of doing this, here 2 I can think off:
Loop through the display list and disable any display objects under your alert depth wise.
Cheat it with a blocker. When you display your alert, display another clip (could have alpha set to 0 ) that blocks the user from hovering/clicking objects. The blocker might need a bit of setup( buttonMode = true, useHandCursor = false, etc. )
This 'modal' behavior has been around for some so there might be no need to reinvent the wheel, depending of your current setup.
If you're using the Flex framework, you've got the functionality in, for Flash you can use the Alert Manager from the Yahoo! Flash Astra Components:
Goodluck,