Placeholder in Flex ActionScript

All the modern browser or mobile apps support a placeholder for the text input field. once you click on it the focus move to the beginning of the text and the placeholder remain until you start typing.

To achieve this using Flex , Actionscript

<mx:Script><![CDATA[

private var sampleText_text:String = "Enter Name";

  protected function sampleText_initializeHandler(event:FlexEvent):void

  {

  //For Place Holder for sampleText

  sampleText.addEventListener(FocusEvent.FOCUS_IN , focusin);

  sampleText.addEventListener(FocusEvent.FOCUS_OUT,focusout);  

  }

  //fire when click to edit

  public function focusin( event:Event ) : void

  {

  if(sampleText.text == sampleText_text)

  {

  sampleText.text = "";

  }

  }

  //fire when you clicked out

  public function focusout(event:Event):void

  {

  if(sampleText.text == "")

  {

  sampleText.text = sampleText_text;

  }

  }

]]></mx:Script>

<mx:HBox paddingTop="10">

<mx:Label text="Name" />

<mx:TextInput id="sampleText" initialize="sampleText_initializeHandler(event)"/>

</mx:HBox>

 

10 Comments

  1. If some one needs to be updated with most recent technologies
    then he must be pay a visit this site and be up to date every day.

  2. Thanks for a marvelous posting! I seriously enjoyed reading it, you will be a great author.

  3. naturally like your web site but you have to check the spelling on several of your posts. Several of them are rife with spelling issues and I find it very bothersome to tell the truth then again I will certainly come back again.

  4. Excellent blog here! Additionally your website loads up fast! What host are you the use of? Can I get your associate link in your host? I want my website loaded up as fast as yours lol

  5. I was recommended this blog by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. Youre incredible! Thanks!

  6. Article writing is also a excitement, if you be familiar with after that
    you can write if not it is difficult to write.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from

Subscribe now to keep reading and get access to the full archive.

Continue reading