It's because the button you click will have the focus. So you should
return the focus on the textfield before you can get the Selection of
the text.

[as]
underline_btn.addEventListener("click", mx.utils.Delegate.create(this,
underline_check));

function underline_check(evt:Object):Void {
        Selection.setFocus(editdesc_txt);
        var startIndex:Number = Selection.getBeginIndex();
        var endIndex:Number = Selection.getEndIndex();
        var strToUnderline:String = editdesc_txt.text.substring(startIndex, 
endIndex);
        trace("String to Underline:
"+strToUnderline+"|B:"+Selection.getBeginIndex()+" |E:
"+Selection.getEndIndex()+" |C:"+Selection.getCaretIndex());
        editdesc_txt.replaceText(startIndex, endIndex, 
"<u>"+strToUnderline+"</u>");
}
[/as]

2006/5/29, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
Can anyone tell me why this outputs -1 for every value? Could it be because the
textfield looses focus when I click on the button component?  I am trying to
get the first and last position of the selected text in a dynamic textfield.
Any pointers would be awesome!


Outputs: String to Underline: |B: -1 |E: -1 |C: -1


var underline_check:Object = new Object();
underline_check.click = function(eventObj:Object) {
        var startIndex:Number = Selection.getBeginIndex();
    var endIndex:Number = Selection.getEndIndex();
    var strToUnderline:String = editdesc_txt.text.substring(startIndex,
endIndex);
        trace("String to Underline: "+strToUnderline + "|B:
"+Selection.getBeginIndex()+ " |E: "+Selection.getEndIndex() + " |C:
"+Selection.getCaretIndex());
    editdesc_txt.replaceText(startIndex, endIndex, "<u>"+strToUnderline+"</u>");

};
underline_btn.addEventListener("click", underline_check);


Boots
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to