Dismiss SoftKeyboard in Flex Mobile - apache-flex

The Flex InteractiveObject has has a requestSoftKeyboard() method that pops up the Soft Keyboard.
How can I do the opposite and send it back?
Thank you.

With Flex 4.6, you can dismiss by setting
stage.focus = null;
Please read more here:
open soft keyboard in a mobile Flex application

For example, say your InteractiveObject is a TextInput, then you can keep it from popping up with the following:
private function onActivating(event:SoftKeyboardEvent):void
{
event.preventDefault();
}
<s:TextInput softKeyboardActivating="onActivating(event)" />
Or you can use
<s:TextInput needsSoftKeyboard = "False"/>
EDIT:
You can send it back with the following:
Listen for the event when you want it to close (like hitting the "enter" key) and then use the setFocus property to change the focus to another component:
private function CloseKeyboard():void
{
hidesoftkeyboard.setFocus();
}`
<s:TextInput id="txtinput"/>
<s:Button id="hidesoftkeyboard" click=CloseKeyboard();>
UPDATE
Following the 4.6 update to Flex - there are new softkeyboard techniques chronicled here.

Related

flex autocomplete change/textEvent not fired

I am trying to make flex autocomplete change its dataprovider at runtime based on user input.
<components:AutoComplete change="change()" id="ac" dataProvider="{_a1}" width="100" />
<s:Button label="change" click="change()" />
private function change():void
{
Alert.show("sdsd");
//Alert.show(event.text);
//ac.dataProvider = _a2;
}
when I click the button, the function get fired, but when i input the text, it doesnt fire.
I was trying to use both change and textEvent, however, none of them are fired.
I wonder if there is any way that i can do this?
Thanks in advance.

view sitching how to?

I have a mxml flex application where I have to launch a VideoPlayer on button click event. Any idea what solutions I can use to open a new "frame" or "view" (I'm not sure what the right terminology is) with the VideoPlayer playing a media clip so that it wouldn't interfere with the original "view"?
What I would do is create a component (like a TitleWindow, Group, Panel, etc.) that has your VideoPlayer added to it and then use the PopUpManager to display it on screen when your button is clicked. Make sure you add a method to close the pop up when you're done with it.
Some links on the PopUpManager to get you started:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/PopUpManager.html
http://blog.flexexamples.com/category/popupmanager/
http://blog.flexexamples.com/2008/03/20/creating-custom-pop-up-windows-with-the-popupmanager-class-redux/
A (really) rough example:
<fx:Script>
<![CDATA[
private var myVideoPlayerComponent:VideoPlayer;
protected function btnHistory_clickHandler(event:MouseEvent):void
{
myVideoPlayerComponent = PopUpManager.createPopUp(this, VideoPlayer, false);
PopUpManager.centerPopUp(myVideoPlayerComponent);
}
]]>
</fx:Script>
<s:Button label="Play" id="myButton" click="myButton_clickHandler(event)" />

How to show hand cursor when mouse is over List component?

I am aware that the follow will show a hand cursor:
component.mouseChildren = true;
component.useHandCursor = true;
component.buttonMode = true;
When I do the above on a List component, the hand button is shown and the whole component loses it's interactivity (Hand cursor is shown even on scrollbars).
So how can I show the hand cursor only when rolling over the list items?
Missread your full test, below is just how to show hand cursor on any Flex control.
I would suggest that you make an custom itemRenderer and for each renderer you use these controls, that will make it show only when you are over the itemRenderer and it will not be applicable for the whole List control...
Check out this blog post I wrote about showing hand cursors on any Flex control.
Showing hand cursor on any Flex Control
Sometimes useHandCursor=true buttonMode=true is enough, but for some controls you have to use mouseChildren=false
Examples:
<mx:Button label="Button" useHandCursor="true" buttonMode="true" />
<mx:Label text="Label" useHandCursor="true" buttonMode="true" mouseChildren="false"/>
I had the same issue with getting a hand cursor over a datagrid. I assume the solution will be the same for lists.
The way I found to get a hand cursor while also having interactivity with items in my datagrid was to use the itemRollOver and itemRollOut events of DataGrid (List has them too):
[Embed("../assets/images/cursors/hand_cursor.png")]
private var handCursor:Class;
protected function grid_itemRollOver():void {
cursorManager.setCursor(handCursor);
}
protected function grid_itemRollOut():void {
cursorManager.removeAllCursors();
}
function meOver(evt:Event):void{
evt.target.useHandCursor = true;
}
myList.addEventListener(MouseEvent.MOUSE_OVER, meOver);

What's the best way to cause a Flex 3 button to respond to the enter key?

In Flex 3, buttons call their click handler when they are clicked on by the mouse, or when they have the focus and the user depresses the space bar.
Is there a straightforward way to cause Flex 3 buttons with focus to call their click handler when the user presses the enter key?
Sure, you could do something like this:
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function btn_click(event:MouseEvent):void
{
Alert.show("Clicked!");
}
private function btn_keyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.ENTER)
btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
]]>
</mx:Script>
<mx:Button id="btn" label="Click Me" click="btn_click(event)" keyDown="btn_keyDown(event)" />
... although I'm not a huge fan of dispatching events on objects outside of those objects. A cleaner approach might be to subclass Button, add the listeners and handlers inside your subclass, and then dispatch the click event from within that class. But this should help illustrate the point. Good luck!
For something like a login form, you need to actually use an mx:form - here's the code snippet that illustrates it:
<mx:Form defaultButton="{loadButton}">
<mx:TextInput id="feedURL" />
<mx:Button id="loadButton" label="Load" click="someHandler(event)" />
</mx:Form>
Enter the url and hit enter, bam, expected behavior.
Googled from here.
If you are submitting a form like a Login dialog or the like, the "enter" property on the TextField is a great solution:
<mx:TextInput displayAsPassword="true" id="wPassword" enter="handleLoginSubmit()"/>
Even better
private function setValidationFocus(formObject:Object):void
{
formObject.setFocus();
formObject.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OUT)); // sneaky sneaky
formObject.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
}
You can also add the KEY_DOWN listener in Christian's answer to the button itself. Just make sure you call stopImmediatePropagation. In this example I let any key cause the button action. And I am using the same handler so I allow any "Event" type. You could use different "cancelClick" handlers.
protected function cancelClick(e:Event = null):void{
this.dispatchEvent(new Event(Event.CANCEL)); // do component action
e.stopImmediatePropagation();
}
override protected function partAdded(partName:String, instance:Object):void {
super.partAdded(partName,instance);
switch(instance){
case cancel:
cancel.addEventListener(MouseEvent.CLICK,cancelClick);
cancel.addEventListener(KeyboardEvent.KEY_DOWN,cancelClick);
}
}
Try the "buttonDown" event; it may be dispatched in either case. Otherwise you are probably looking at using "keyDown" and checking the key that was pressed.
I've been lookind at the same problem but the answer from Christian Nunciato seem's to me to be the best.
One more thing to add to his solution, I think that the bubbling, flag in btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK)), should be set to false (btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK, false))) because
the event should be isolated on the button.

How to warn user of CAPS LOCK enabled in Flex/AIR?

Similar to the XP login screen, in Flex 3, how can I display a warning to the user in a textbox that the CAPS LOCK key is enabled?
flash.ui.Keyboard.capsLock is not bindable so that code won't really work.
I would invoke a function in the "keyDown" event for the TextInput and then check flash.ui.Keyboard.capsLock in that function. You can then set visible/includeInLayout on that Text, pop up an Alert, etc...
try this
private function addHandler():void{
//Called from app's creation complete event.
//Listener to handle any keyboard KEY_DOWN event:
this.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown);
}
private function handleKeyDown(event:KeyboardEvent):void{
if (Keyboard.capsLock){
lblCaps.visible =true;
} else {
lblCaps.visible =false;
}
}
call addHandler on creation complete
In actionScript:
if(flash.ui.Keyboard.capsLock){
// caps lock is on...
}
or MXML:
<mx:Box width="100%" id="capsbox"
visible="{flash.ui.Keyboard.capsLock}"
includeInLayout="{capsbox.visible}">
<mx:Text text="Caps Lock is on." color="red" />
</mx:Box>

Resources