2009-03-11 29 views
2

Metin Alanı kullanarak bir metin düzenleyicisi yapıyorum. Yazı boyutunu, ailesini ve vb değiştirebilir hangi kullanıcı
Bu şekilde benim kodudur:Esnek: Metin Alanı Değiştirme

<mx:ComboBox x="78" y="8" width="114" id="cmbbxFntFam" close="ChangeFont(event)"></mx:ComboBox> 

Ben yazı tipini nasıl değiştirebilirim:

private function ChangeFont(event: Event):void 
     { 
     var mySelectedTextRange:TextRange = new TextRange(thistxtarea,true, 
               thistxtarea.selectionBeginIndex, 
               thistxtarea.selectionEndIndex); 
     mySelectedTextRange.fontSize = int(cmbbxFntSze.text); 
     thistxtarea.setFocus(); 
     } 

i istenen yazı tipi boyutunu girmek için bu açılan kutu var içindeki metin vurgulanmamışsa özellikler? Örneğin, fare işaretçisini Metin Alanımın içindeki metinlerin son dizinine konumlandırıyorum ve açılan kutumda istediğiniz yazı tipi boyutunu seçiyorum. Metin Alanı'nda girilen harfin aşağıdaki yazı tipi boyutu açılan kutuda seçilen yazı tipi boyutu olmalıdır. Göndermiş olduğum kod sadece istenen metni vurguladığımda çalışır.

cevap

1

Bu

private function setTextStyles(type:String, value:Object = null):void 
     { 
      if(thisindex != -1) 
      { 
       var tf:TextFormat; 

       var beginIndex:int = textArea.getTextField().selectionBeginIndex; 
       var endIndex:int = textArea.getTextField().selectionEndIndex; 

       textArea.getTextField().alwaysShowSelection = true; 

       if (beginIndex == endIndex) 
       { 
        tf = previousTextFormat; 
       } 
       else  
        tf = new TextFormat(); 


       if (type == "bold" || type == "italic" || type == "underline") 
       { 
        tf[type] = value; 
       } 
       else if (type == "align") 
       { 
        if (beginIndex == endIndex) 
        { 
         tf = new TextFormat(); 
        } 

        // Apply the paragraph styles to the whole paragraph instead of just 
        // the selected text 
        beginIndex = textArea.getTextField().getFirstCharInParagraph(beginIndex) - 1; 
        beginIndex = Math.max(0, beginIndex); 
        endIndex = textArea.getTextField().getFirstCharInParagraph(endIndex) + 
         textArea.getTextField().getParagraphLength(endIndex) - 1; 
        tf[type] = value; 
        previousTextFormat[type] = value; 
        if (!endIndex) 
         textArea.getTextField().defaultTextFormat = tf; 
       } 
       else if (type == "font") 
       { 
        tf[type] = cmbbxFntFam.text; 
       } 
       else if (type == "size") 
       { 
        var fontSize:uint = uint(cmbbxFntSze.text); 
        if (fontSize > 0) 
         tf[type] = fontSize; 
       } 
       else if (type == "color") 
       { 
        tf[type] = uint(clrpckerFontColor.selectedColor); 
       } 


       textFormatChanged = true; 

       if (beginIndex == endIndex) 
       {      
        previousTextFormat = tf; 
       } 
       else 
       { 
        textArea.getTextField().setTextFormat(tf,beginIndex,endIndex);//textArea.setTextFormat(tf,beginIndex,endIndex); 
       } 

       dispatchEvent(new Event("change")); 

       var caretIndex:int = textArea.getTextField().caretIndex; 
       var lineIndex:int = textArea.getTextField().getLineIndexOfChar(caretIndex); 

       textArea.invalidateDisplayList(); 
       textArea.validateDisplayList(); 
       textArea.validateNow(); 

       // Scroll to make the line containing the caret under viewable area 
       while (lineIndex >= textArea.getTextField().bottomScrollV) 
       { 
        textArea.verticalScrollPosition++; 
       } 

       callLater(textArea.setFocus); 

      } 
     } 

Bu kod ben bu kodu textArea

private function getTextStyles():void 
     {    

      if (!textArea) 
       return; 

      var tf:TextFormat; 

      var beginIndex:int = textArea.getTextField().selectionBeginIndex; 
      var endIndex:int = textArea.getTextField().selectionEndIndex; 

      if (textFormatChanged) 
       previousTextFormat = null; 

      if (beginIndex == endIndex) 
      { 
       tf = textArea.getTextField().defaultTextFormat; 
       if (tf.url != "") 
       { 
        var carIndex:int = textArea.getTextField().caretIndex; 
        if (carIndex < textArea.getTextField().length) 
        { 
         var tfNext:TextFormat=textArea.getTextField().getTextFormat(carIndex, carIndex + 1); 

         if (!tfNext.url || tfNext.url == "") 
          tf.url = tf.target = ""; 
        } 
        else 
         tf.url = tf.target = ""; 
       } 
      } 
      else 
       tf = textArea.getTextField().getTextFormat(beginIndex,endIndex);     


      if (cmbbxFntSze.text != tf.font) 
       setComboSelection(cmbbxFntFam, tf.font); 
      if (int(cmbbxFntSze.text) != tf.size) 
       setComboSelection(cmbbxFntSze,String(tf.size)); 
      if (clrpckerFontColor.selectedColor != tf.color) 
       clrpckerFontColor.selectedColor = Number(tf.color); 

      if (btnBold.selected != tf.bold) 
       btnBold.selected = tf.bold;//Alert.show("bold"); 
      if (btnItalic.selected != tf.italic) 
       btnItalic.selected = tf.italic; 
      if (btnUnderline.selected != tf.underline) 
       btnUnderline.selected = tf.underline; 


      if (tf.align == "left") 
       alignButtons.selectedIndex = 0; 
      else if (tf.align == "center") 
       alignButtons.selectedIndex = 1; 
      else if (tf.align == "right") 
       alignButtons.selectedIndex = 2; 
      else if (tf.align == "justify") 
       alignButtons.selectedIndex = 3; 



      if (textArea.getTextField().defaultTextFormat != tf) 
       textArea.getTextField().defaultTextFormat = tf; 
      previousTextFormat = tf; 
      textFormatChanged = false; 

      lastCaretIndex = textArea.getTextField().caretIndex;     
      thishtmltxt = textArea.htmlText; 
      textArea.validateNow(); 
     } 

minör hatalarını kontrol edin, kuzen gelen stil almak için kullanılması i bazı yorumladı edilir

stile ayarlamaktır izler

0

mx.controls.RichTextEditor bunu nasıl yaptı? İçeri bulabilirsiniz ... \ çerçeveler \ projeler \ çerçeve \ src \ mx \ kontrolleri

Eğer RichTextEditor o tutar TextFormat değişkenine geçerli yazı stili ayarları korur göreceksiniz bu kodu tararsanız

, ve sonra bu stili yeni girilen metne uygular. Bu değişken, kullanıcı fontları/boyutları değiştirdiğinde veya seçim komşu stilini kapmak için değiştiğinde güncellenir. Seçim durumundaBeginIndex == selectionEndIndex için de özel bir dikkat var.

+0

Merhaba. Ne önerdiğini gözden geçirdim ama bu metin gibi anlamadığım bazı kodlar varArea.getTextField(). SetTextFormat textArea özellikleri getTextField.Where nereden geliyor? Lütfen bana nasıl yardımcı olabileceğime yardım edin. – Jejad

+0

getTextField(), mx_internal ad alanında. Bu ad alanını sınıfınıza içe aktarmanız ve açmanız ya da açık önek getTextField() (ör. Mx_internal :: getTextField()) –

+0

merhaba. Herkes bunu TextArea çalışma zamanı oluşturma üzerinde uyguladı? Lütfen bana nasıl yapılacağına dair bana bir örnek verin. Fonksiyonu geçersiz kılmak için zor bir zamanım var. – Jejad