Loss of mouseOver focus when using setInterval and setFocus
I am ripping my hair out due to what seems to me bizarre behavior by flash.
I have a demo that simulates a real device so has a number of buttons. These can be pressed to give different text input depending on whether they are just pressed or the user presses and holds on them.
The problem is that I want to put the focus back to the input Box and have a flashing cursor at the end. But every time I do this the button that has the mouse over it looses focus. As in mouseOver is lost. If you then move the mouse a tiny bit the mouseOver focus comes back. This problem means that the user has to do an extra click to get the mouse focus back and it makes it feel like the demo is broken. Here is my code. It is based on the idea that there is a button called "num4" and an input box called "testInput" on the stage.
I have to use setInterval as I need maximum control over the timings. Something I cannot have from code based on workarounds using a movieClip with code embedded in it.
Thanks, but this still does not help. As the problems exists when the mouse is not being moved I am not sure how onMouseMove can help. The mouse stays in the same place during the setFocus code. Any other ideas?
If you set the focus to a text field, the button no longer has the focus, so will no longer appear in it's over (or down) state by default. So, don't use a button -- use a movie clip instead, and write the code to make the clip change between different states exactly when you want it to.
Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com
Sorry my previous post was far too brief I have replaced the buttons with movieclips and used code like rollOut, roolOver, onPress, onRelease, onDragOut etc to simulate all the possible things a button does. But the problem still exists. I even changed the demo so that instead of setInterval I have a movieClip that plays and when the head hits the end some code runs to change focus. This too suffers with the same problem. The second setFocus works the entire movie looses the ability to recognise that the mouse is over anything (reflected by the cursor no longer being a hand and instead being the standard system cursor). It will only start focusing buttons again if I wiggle the mouse. Something that is not good enough for my project. Thanks for putting in the time to help. It really is appreciated.
Sadly I cannot use that type of code. I am trying to replicate the exact behavior of text entry via a mobile phone keyboard. Take the 2 key. You can hold it down for half a second to get '2'. Or you can press it once for 'a', twice for 'b' and so on. After one second the cursor appears so you can enter the next character. So I cannot have the focus appearing just based on mouse move.
I have attached a cut down version with just a '2' key from the telephone. In code ther is only one array, but in the real app each key has a seperate array. this is why there is the odd code "_root["keyNumber" + keyNum1][0]". To see the problem just press the phone key once and after a second you will see it looses focus. I have only been coding 3 months so am still getting the hang of writing readable actionscript. Just ask if you want to know why I am doing anything.
The same approach should work. Do not use rollOver since that will be undone when focus is set elsewhere. Instead, I think onMouseMove is really what you need.
Use onMouseMove code to send the key movieclip to its highlighted state, as in my code. This will have nothing to do with rollOver, so it will not be affected when the focus goes to the textfield.
Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com
Nope, this still does not work. All this does is give the illusion of a focused button. It looks like the button is focused. However, once the cursor appears in the text field I need to again click the mouse or wiggle the cursor to get focus (as in the button will now do something). I then click again and the button does its job. It is like setFocus takes away focus from the entire movie until it is clicked on again or the cursor is wiggled.
No, setFocus just takes the focus away from the button when it gives focus to the text field. For your application, you need to do explicitly what we usually rely on onRollOver and other events handlers to do. So, in the function that you call using setInterval, you need to explicitly check:
is the mouse still over the button? If no, clear interval and return.
has the mouse been released yet? If yes, clear interval and return.
if we survive those tests, then increment the letter displayed.
--------
Another approach would be to change the content of the text field, but keep the focus on the button.
Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com
okay. Thanks a lot for all your help. I will see if I can still get an event listner for the mouse click. If I can then I will just have some code to remember what the last button to have focus was and perform that action. If that fails I will give up :-)