• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1905
  • Last Modified:

Flex 4.5 Spark textInput get focus

Hi Experts,

I have a little test app that I am playing with and when it loads in the browser I would like the textinput box to have focus so I can start typing and the characters and they appear in the textbox without first clicking the textbox.

My current code brings focus to the textinput but doesn't allow me to start typing without first clicking the text box.  I just want to load the page and if I immediately begin typing, the characters appear in the textbox.

How can I correct this?

Thanks!

HNM
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   width="240" minWidth="240" minHeight="600" pageTitle="test app" creationComplete="creationCompleteHandler()">
	
	<fx:Script>
		<![CDATA[
			import spark.components.Label;
			
			private function creationCompleteHandler():void
			{
				focusManager.setFocus(scannedBarcode);
			}
			protected function button1_clickHandler(event:MouseEvent):void
			
			{
				// TODO Auto-generated method stub
				var barcodeEcho:Label = new Label();
				barcodeEcho.text = scannedBarcode.text;
				container.contentGroup.addElement(barcodeEcho);
			}
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
<s:BorderContainer id="container" height="300" width="240" borderStyle="inset"
			borderColor="#cccccc" borderWeight="4">
	<s:layout>
		<s:VerticalLayout>
			
		</s:VerticalLayout>
	</s:layout>
	<s:TextInput id="scannedBarcode"/>
	<s:Button label="Echo Barcode" click="button1_clickHandler(event)"/>
</s:BorderContainer>

</s:Application>

Open in new window

0
HelpNearMe
Asked:
HelpNearMe
3 Solutions
 
PluckaCommented:
You cant, the flash container needs a click to get focus first. Its a common questions, there are work arounds for some browsers but not all.
0
 
PluckaCommented:
You could try this which claims to work in all browsers
http://www.flexjunk.com/2010/12/30/managing-initial-swf-focus-in-all-browsers/
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ChristoferDutzCommented:
Using the dynamic publishing method of SWFObject claims to avoid the click-to-activate stuff for flash. Mabe this helps?
http://code.google.com/p/swfobject/wiki/documentation (read the "Should I use the static or dynamic publishing method?" section)
0
 
HelpNearMeAuthor Commented:
Still trying these solutions.. I'll be back soon.  Thanks
0
 
HelpNearMeAuthor Commented:
Thanks for the help.  I'm having some serious problems just getting flash to work on the handheld.  So I'm going to close this question.  Thanks again.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now