That is in the focusIn handler.

  <mx:TextInput id="ti" focusIn="removeSelection()" />
  <mx:Script>
    private function removeSelection():void
    {
      ti.selectionBeginIndex = 0;
      ti.selectionEndIndex = 0;
    }
  </mx:Script>

On 5/1/07, Alex Harui <[EMAIL PROTECTED]> wrote:
>
>
>
>
> selectionBeginIndex = selectionEndIndex = 0
>
>
>
>  ________________________________
>
>
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of barry.beattie
>  Sent: Tuesday, May 01, 2007 10:16 AM
>  To: flexcoders@yahoogroups.com
>  Subject: [flexcoders] when is setFocus() not?
>
>
>
>
>
>
> 1) Q: have I picked the wrong method and setFocus() is NOT what I want
>  - or - do I have to construct exactly what I want piece by piece?
>
>  [full code below]... I've got a TextInput that updates the underlying
>  XML when it loses focus (which it does OK). When the buttons are used,
>  it returns the focus back to the TextInput (which is sort-of does).
>  the bit I don't like is previously entered value itself have the
>  focus, ready to be wiped with an accidental keystroke.
>
>  What I really want is to place the cursor either in front or back of
>  the value so the user has to use the delete or backspace key (or
>  mouse) to delete/replace the value. I prefer at the back since plenty
>  of Mac users have forgotten "fn-delete" deletes forwards, not back.
>
>  do I have to do this piece by piece or is there something better than
>  setFocus(). doing this for a couple of controls is OK but I've got
>  lots to do in reality.
>
>  2) Q: is there any work being done to simplify setting of tab-orders,
>  shortcut keys and key stroke listeners? I've got (many) dozens of form
>  elements in each view driven off business logic - doing it before in
>  Javascript was a right royal pain, I was hoping Flex had it easier.
>
>  the end users are data entry ppl who rarely use mouses (mice?) and are
>  very fussy about how the UI performs for data entry (focus, tab
>  order, short-cut keys, etc)
>
>  any suggestions to make my life easier?
>  thanx
>
>  [watch out for text wrap and broken lines]
>  ------------------------------------
>  <?xml version="1.0" encoding="utf-8"?>
>  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
>  layout="absolute"
>  applicationComplete="init()"
>  >
>  <!-- NOTE: this just something thrown together to illustrate the
>  problem -->
>  <mx:Script>
>  <![CDATA[
>  import mx.effects.Blur;
>  [Bindable]
>  private var cursor:int = 0;
>  private var firstIndex:int = 0;
>  private var lastIndex:int = 0;
>  [Bindable]
>  public var questionaire:XML;
>
>  private function init():void{
>  questionaire = <questionaire>
>  <question category="Brielly" id="71" weight="2" rating=""
>  text="Unit Test Frameworks" />
>  <question category="Brielly" id="72" weight="1" rating=""
>  text="The Cathedral & the Bazaar" />
>  <question category="Maddison" id="10" weight="1"
>  rating="" text="Design Patterns" />
>  <question category="Maddison" id="11" weight="1"
>  rating="" text="The Pragmatic Programmer" />
>  <question category="Maddison" id="12" weight="3"
>  rating="" text="Refactoring to Patterns" />
>  <question category="Maddison" id="15" weight="2"
>  rating="" text="Test Driven Development" />
>  <question category="O'Reilly" id="13" weight="1"
>  rating="" text="Agile Development" />
>  </questionaire>;
>  lastIndex = questionaire.children().length()-1; //
>  zero-based index/arrays!
>  first();
>  }
>
>  private function first():void{
>  cursor = 0;
>  btnFirst.enabled=false;
>  btnBack.enabled=false;
>  if(!btnNext.enabled){btnNext.enabled=true}
>  if(!btnLast.enabled){btnLast.enabled=true}
>  }
>
>  private function back():void{
>  cursor--;
>  if (cursor == firstIndex){
>  btnFirst.enabled=false;
>  btnBack.enabled=false;
>  }
>  if(!btnNext.enabled){btnNext.enabled=true}
>  if(!btnLast.enabled){btnLast.enabled=true}
>  }
>
>  private function next():void{
>  cursor++;
>  if (cursor == lastIndex){
>  btnNext.enabled=false;
>  btnLast.enabled=false;
>  }
>  if(!btnFirst.enabled){btnFirst.enabled=true}
>  if(!btnBack.enabled){btnBack.enabled=true}
>  }
>
>  private function last():void{
>  cursor = lastIndex;
>  btnNext.enabled=false;
>  btnLast.enabled=false;
>  if(!btnFirst.enabled){btnFirst.enabled=true}
>  if(!btnBack.enabled){btnBack.enabled=true}
>  }
>
>  private function onRatingChange(event:Event) :void{
>  [EMAIL PROTECTED] = event.currentTarget.text;
>  // HERE: focus not quite right <<<<<<<<<<<<<<<<<<<<<<<<<<
>  event.currentTarget.setFocus();
>  }
>  ]]>
>  </mx:Script>
>  <mx:VBox x="197" y="131" height="100%" width="100%">
>  <mx:HBox width="100%">
>  <mx:TextArea width="100%" height="100%" id="questionText"
>  text="[EMAIL PROTECTED]"/>
>  </mx:HBox>
>  <mx:HBox width="100%">
>  <mx:Button label="|&lt;" id="btnFirst" click="first()" />
>  <mx:Button label="&lt;&lt;" id="btnBack" click="back()"/>
>  <mx:Text text="{cursor}"/>
>  <mx:TextInput id="txtWeight"
>  text="[EMAIL PROTECTED]"
>  focusOut="onRatingChange( event )"/>
>  <mx:Button label="&gt;&gt;" id="btnNext" click="next()"/>
>  <mx:Button label="&gt;|" id="btnLast" click="last()"/>
>  </mx:HBox>
>  </mx:VBox>
>
>  </mx:Application>
>
>  -----------------------------------
>
>  

Reply via email to