How do I refresh the mouse cursor after I remove focus from a TextField? - actionscript-3

I want to remove focus and selection on a textfield, if the user types ESC or ENTER, or focuses somewhere else. Thus I do this:
stage.focus = null;
textField.type = TextFieldType.DYNAMIC;
textField.selectable = false;
textField.mouseEnabled = false;
The problem is that, if the mouse is over the editable text field, the mouse is in IBEAM mode (caret cursor) and remains in IBEAM mode, even after the commands above, untill I slightly move the mouse, at which point it returns to the AUTO state.
I want to force the mouse to update itself and satisfy the AUTO state but no matter how much I try to make sure the textfield is disabled, it won't dissapear on its own, only after I move the mouse a bit.

Simplest answer from your comment:
So I was fidling with your suggestion and for the luls, used Mouse.hide() and then Mouse.show() and it worked. Removed the hide() and it works just with Mouse.show()! Guess it refreshes the mouse cursor. No blink, works perfectly <3
My original answer:
This is sort of a workaround but shouldn't be too difficult to implement. Hopefully someone comes along with a native API solution.
Run your code you posted
Then make cursor invisible
Then place your custom cursor at the mouse position (optional if you don't mind the cursor just disappearing)
On MouseEvent.MOUSE_MOVE remove your custom cursor, and make the cursor visible again.
I doubt you need me to write this code for you, but if you think this method would work for you, and you have a problem implementing this technique, let me know.
If you're worried about different systems having different mouse icons and then suddenly getting your custom one for a split second, the easy solution there is to just always use your custom cursor. You can design it to look exactly as you like; either mimic Windows OS or make it unique.

Related

AS3 Making a button work on one scene and does nothing on all other scenes.

I basically have 50 buttons and 50 scenes. Each scene has a corresponding button that is "correct". When a user clicks the correct button, I want it to go to the next scene AND also make that button not-clickable anymore. I have everything functioning except for the not-clickable part and this is an issue because whenever i click on a state that already has been selected as the right answer, it'll jump me back to the question that was supposed to follow it. I'd show my code, but it is just 50 buttons and a buttonClick function and that's it.
Thanks in advance.
You could call
yourButton.removeEventListener(MouseEvent.CLICK,yourFunction);
or you could call
yourButton.mouseEnabled = false;
yourButton.mouseChildren = false;
Hard to help without any code.

Reliably detect if a user is using a mouse on a webpage?

On our page we have some iframes in a long horizontally-scrolling <div>. If the user is using a mouse they can scroll with the scrollbars and we would like them to be able to select text within the iframes. If they are using touch only however, the scrollbars are a hassle and I would like to overlay a transparent element over the whole thing to give them the ability to scroll easily by dragging, this of course sacrifices the select-text feature but makes sense in that scenario.
Which gets me to my question, is there a way to reliably detect if a user is interacting with a webpage via a mouse?
Everything I've seen on detecting touch or mouse is that touch will broadcast mouse events so it is very difficult to detect touch OR mouse (not to mention that you can have both). My problem is simpler - it is whether the user has interacted with the page via a mouse.
Can anyone think of a way to check this reliably?
A mouse can do one single thing a touch device can never do - move without having any buttons pressed. So I'd just install an onMouseMove event on page load, and if it triggers without buttons pressed mark the user as a mouse user. You could then persist this through a cookie or LocalStorage since the flag will not change within the same environment, and remove the event right away. The precise way of implementing the single-fire event depends on which library you use (if any at all), but it should be easy with Mootools/JQuery docs in hand.
In general I'd recommend the easier route of just checking for a touch interface in most cases :
if('ontouchstart'in window)
{
/* it's a touch device */
}

Page flip effect on button press in html5

I'm looking at this:
http://www.netmagazine.com/tutorials/create-page-flip-effect-html5-canvas
However, I have one problem with that - I need to be able to click on the pages, even the edges, without triggering the page turn. I want the pages to turn when a button outside of the canvas is pressed. Is this possible using the base they provided, or do I need to go an entirely different direction?
Yes that can be done.
From what i can see, you need a click event that doesnt trigger the page drag. You need to assign a flag for this.
Let Drag = mouse drag/mouse move, down = mouse down, release = mouse release events respectively.
Initialize your flag variable as false. When a drag event is encountered it becomes true. Otherwise it remains false. As long as it is false when the mouse release event occurs it can be treated as a click. Thats the basic principle behind using mousedown and mouseup as a click event.
You will have to use e.srcElement or e.target to give you the element your cursor is currently positioned over inorder to trigger click functions relative to that element.
If you want a more detailed explanation on the page flip technique then check this out. Helped me lot.

Button removed with removeChild() gets re-added in it's over state

I have a SimpleButton on the stage, and in the click event for it, I remove it using removeChild(). When re-adding the button, it gets re-added in it's "over" state, not the "up" state as expected.
I'm pretty sure it's a bug, so I've filed a JIRA: http://bugs.adobe.com/jira/browse/SDK-31445, my question is now on how to fix it, if anybody's had a similar experience.
What I've tried:
using visible = false instead works, but I'd prefer to remove it off the stage altogether as the game I'm working on can have a lot of popups/screens.
Firing the mouse_out event manually - doesn't work, and in any case, the mouse_out event fires as expected (perhaps before resetting to the up state, it makes a check to see if it's added to the stage, finds out it's not, then quits early)
Resetting the stage focus - I thought it was a problem with the stage focus, as you were losing focus when the button was hidden, but resetting it didn't fix it.
I could temporarily swap the over and up state when it's hidden, but that seems like an ugly fix.
I've been Having this problem as well, removing one button and adding another in response to an Mouse up event on a separate sprite.. IE the mouse isn't over either of the buttons at the time, But when the first button (the one with the problem) was previously removed the mouse was indeed over it so it hadn't received a mouseOut event and retained itself in the over state. Using visibility to work round this which is ok for my needs BUT the alternative answer would be to replace with a new instance of the button before adding it to the Display List.

How to get cursor to follow text when reading a web page?

I know this isn't strictly program related, but I think I've seen this answer on SO before and lost track of it.
The specific question has to do with reading an electronic document. I find it helpful to move the cursor across the words as I'm reading them. This works great with Word documents, but I'm unable to do it with web pages. Is there a way to make a web page see and respond to cursor movement?
I'm not sure what you actually want to do when the cursor moves, but you can capture mouse movements over an element with said element's onMouseMove event.
Like this:
<div id="a" onMouseMove="doSomething(event.clientX, event.clientY)">
Mouse over me!
</div>
This will send the current X and Y coordinate to the "doSomething()" function when the mouse is moved over the DIV
In Firefox, you can do this by going to about:config and modifying the accessibility.browsewithcaret setting. (Type "caret" into the filter field, and right click to change the value of a boolean setting)