Sono arrivato fin qui, ma il problema nasce quando si fa una selezione che è tra vari tag ovvero:

non riesce a prendere l'indexOf del testoHTML in questo caso:

testoHTML="<a>Prova TUTTO</a> ma Stai ATTENTO e ora SELEZIONA"

selezione="O</a> ma";

inizio=testoHTML.indexOf(selezione);

RISULTATO=-1;

Questo comunque è lo script che stò elaborando:

Codice PHP:
System.useCodepage true;
this.createTextField("my_txt"this.getNextHighestDepth(), 1010320240);
my_txt.border true;
my_txt.wordWrap true;
my_txt.multiline true;
my_txt.type "input";
my_txt.html true;
my_txt.htmlText "<a>Prova TUTTO</a> ma [b]Stai ATTENTO[/b] e ora SELEZIONA";
var 
my_cm:ContextMenu = new ContextMenu();
my_cm.customItems.push(new ContextMenuItem("Sottolineatura"sottolinea));
my_cm.customItems.push(new ContextMenuItem("Grassetto"sottolinea));
function 
sottolinea(obj:ObjectmenuItem:ContextMenuItem) {
  var 
mnuItem:String menuItem.caption;
  var 
testoHtml:String my_txt.htmlText;
  var 
testo:String my_txt.text;
  var 
ltxth:Number testoHtml.length;
  var 
ltxt:Number testo.length;
  var 
inizioSel:Number Selection.getBeginIndex();//Inizio selezione;
  
var fineSel:Number Selection.getEndIndex();//Fine selezione;
  
var selezione:String testo.substring(inizioSel,fineSel);//testo selezionato NON HTML
  
var inizioSelh:Number=testoHtml.indexOf(selezione);//Inizio selezione nel testo HTML
  
var fineSelh:Number=inizioSelh+selezione.length;
  var 
selezioneh:String testoHtml.substring(inizioSelh,fineSelh)//testo selezionato HTML
  
var prima:String testoHtml.substring(0,inizioSelh);//Testo HTML prima della selezione
  
var dopo:String testoHtml.substring(fineSelh);//Testo HTML dopo della selezione
  
switch (mnuItem){
  case 
"Sottolineatura":
      
tagA="<u>";
      
tagB="</u>";
      break;
  case 
"Grassetto":
      
tagA="[b]";
      
tagB="[/b]";
      break;
  }
  
my_txt.htmlText prima tagA selezioneh tagB dopo;
}
my_txt.menu my_cm
Chi sà darmi una risposta? o magari una soluzione differente