2009-03-11 4 views
2

텍스트 영역을 사용하여 텍스트 편집기를 만들고 있습니다. 글꼴 크기, 가족 등을 변경할 수있는 사용자
이는 내 코드입니다 :플렉스 : 텍스트 영역 수정

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

내가 글꼴을 변경하려면 어떻게해야 :

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

내가 원하는 글꼴 크기를 입력하려면이 콤보 상자가 내부 텍스트가 강조 표시되지 않는 경우 속성? 예를 들어, 내 텍스트 영역 내에서 마지막 텍스트 인덱스에 마우스 포인터를 놓고 원하는 콤보 상자에서 원하는 글꼴 크기를 선택합니다. 텍스트 영역에 입력 된 다음 글자 크기는 콤보 상자에서 선택한 글꼴 크기 여야합니다. 내가 게시 한 코드는 원하는 텍스트를 강조 표시 한 경우에만 작동합니다.

답변

1

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); 

      } 
     } 

가이 코드는 내가이 코드를 텍스트 영역

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(); 
     } 

사소한 오류를 확인하시기 바랍니다, 사촌에서 스타일을 얻기를위한 사용은 내가 어떤 댓글을 달았됩니다

스타일을 설정하는 것입니다 흔적

0

mx.controls.RichTextEditor은 어떻게 처리 했습니까? 당신은에서 찾을 수 있습니다 ... \ 프레임 워크 \ 프로젝트 \ 프레임 워크 \ SRC \ MX \ 컨트롤

당신이 RichTextEditor는 그것을 유지 된 TextFormat 변수에 현재 텍스트 스타일 설정을 유지 것을 볼 것이다 코드를 스캔하면

, 새로 입력 한 텍스트에이 스타일을 적용합니다. 이 변수는 사용자가 글꼴/크기를 변경하거나 인접 스타일을 선택하기 위해 선택이 변경 될 때 업데이트됩니다. selectionBeginIndex == selectionEndIndex의 경우도 특별히 고려해야합니다.

+0

안녕하세요. 나는 당신이 제안한 것을 복습하지만이 textArea.getTextField(). setTextFormat textArea에는 getTextField.Where라는 속성이 없다는 것을 이해하지 못하는 코드가 있습니다. 알아내는 방법을 알려주세요. 감사합니다. – Jejad

+0

getTextField()는 mx_internal 네임 스페이스에 있습니다. 클래스에 네임 스페이스를 가져 와서 열거 나 getTextField() (즉, mx_internal :: getTextField())를 명시 적으로 접두사로 추가해야합니다. –

+0

안녕하세요. 누구나 TextArea의 런타임 작성시이 기능을 구현 했습니까? 어떻게 수행 할 지에 대한 예를 들어 주시겠습니까? function.thank를 오버라이드하는 데 어려움을 겪고 있습니다. – Jejad