1 Reply Latest reply on Oct 17, 2006 11:07 AM by leotemp

    Help: anyone know this problem?

    mycat13
      Hi all, I have a problem but don't know how to handle it. I have follow code.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" initialize="init();">
      <mx:Label id="lblText" />
      <mx:TextArea text="Hello this is flex world!" id="txaContent"/>
      <mx:Label id="lblMessage"/>
      <mx:TextArea id="txaMessage" width="300" height="300"/>
      <mx:Button label="position" click="onClick(event)"/>
      <mx:Script>
      <![CDATA[
      private function init():void{
      lblText.htmlText = "<i>hello</i>";
      }
      private var count:int = 0;
      private function onClick(e:MouseEvent):void{
      count++;
      txaMessage.text += "click " + count + "th. ";
      txaContent.setSelection(0, 5);
      txaMessage.text += "start : " + txaContent.selectionBeginIndex + " . end : " + txaContent.selectionEndIndex + "\n";
      lblMessage.text = txaContent.text.substr(txaContent.selectionBeginIndex, txaContent.selectionEndIndex);
      }

      ]]>
      </mx:Script>
      </mx:Application>

      I suppose the selectionBeginIndex of txaContent is 0 and and txaContent.selectionEndIndex is 5 when I click button
      . but its 0 and 0 for first time click. and will be 0 and 5 for second time click.

      anyone has idea about this?

      thanks

        • 1. Re: Help: anyone know this problem?
          leotemp Level 1
          well for one, in your
          txaMessage.text += "click " + count + "th. ";
          you need to convert your count var to a string, it should read
          txaMessage.text += "click " + count.toString() + "th. ";
          the same is true with
          txaMessage.text += "start : " + txaContent.selectionBeginIndex + " . end : "
          it should read
          txaMessage.text += "start : " + txaContent.selectionBeginIndex.toString() + " . end : "
          and also
          lblMessage.text = txaContent.text.substr(txaContent.selectionBeginIndex, txaContent.selectionEndIndex);
          should read
          lblMessage.text = txaContent.text.substr(txaContent.selectionBeginIndex.toString(), txaContent.selectionEndIndex.toString());

          At least i think thats a problem, i allways use the toString method when im viewing variables as strings unless i implicitly declared them as strings to begine with.