Flex 4.5 Spark textInput get focus

Posted on 2011-05-09
Last Modified: 2012-05-11
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?


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx=""
			   width="240" minWidth="240" minHeight="600" pageTitle="test app" creationComplete="creationCompleteHandler()">
			import spark.components.Label;
			private function creationCompleteHandler():void
			protected function button1_clickHandler(event:MouseEvent):void
				// TODO Auto-generated method stub
				var barcodeEcho:Label = new Label();
				barcodeEcho.text = scannedBarcode.text;
		<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:BorderContainer id="container" height="300" width="240" borderStyle="inset"
			borderColor="#cccccc" borderWeight="4">
	<s:TextInput id="scannedBarcode"/>
	<s:Button label="Echo Barcode" click="button1_clickHandler(event)"/>


Open in new window

Question by:HelpNearMe
    LVL 29

    Accepted Solution

    LVL 18

    Expert Comment

    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.
    LVL 18

    Assisted Solution

    You could try this which claims to work in all browsers
    LVL 20

    Assisted Solution

    Using the dynamic publishing method of SWFObject claims to avoid the click-to-activate stuff for flash. Mabe this helps? (read the "Should I use the static or dynamic publishing method?" section)

    Author Comment

    Still trying these solutions.. I'll be back soon.  Thanks

    Author Closing Comment

    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.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
    In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now