2012-03-07 4 views
0

TextFieldのスタイルを更新しようとしています。 color、fontSize、fontFamily。その後、私は更新テキストフィールドにしようとしているTextFieldのスタイルシートを更新しても効果がありません。

var textField:TextField = new TextField(); 

var style:StyleSheet = new StyleSheet(); 
style.parseCSS("p{color: #000000; fontFamily: System; fontSize: 20px;}"); 

     textField.styleSheet = style; 

     textField.selectable = false; 
     //textField.embedFonts = true; 
     textField.antiAliasType = AntiAliasType.ADVANCED;   

     ///textField.defaultTextFormat = myFormat; 
     textField.text = text; 
     textField.wordWrap = true; 

     textField.width = 800; 
     textField.height = 40; 

     some_other_mc.addChild(textField); 

: は私がして、フィールドを作成してい

private function SetStyle(name:String, value:String):void { 

     var current_styles:Object = _active_text_field.styleSheet.getStyle('p'); 

     switch(name) { 

      case 'color': 
       current_styles.color = value; 
      break; 

      case 'fontSize': 
       current_styles.fontSize = value; 
      break; 

      case 'fontFamily': 
       current_styles.fontFamily = value; 
      break; 

     } 

     _active_text_field.styleSheet.setStyle('p', current_styles); 

    } 

_active_text_fieldテキストフィールドにリンクされています。

すべてのトリガSetStyleは変更されません。私は長い間バグを見つけることができません。

してくださいと任意の助けをありがとう:)

+0

を取る勧め、あなたがテキストフィールドのための第1セットのスタイルを見ていますか? – Triode

+0

@ rajesh.adhiはい – PiKey

+0

あなたのコードとあなたのSetStyle関数を試しましたが、期待どおりに動作しています...あなたの文字列 "text"変数内のテキストには、HTML

(段落)タグがありますか? – danii

答えて

0

を私はあなたがこの簡単なサンプル

package { 
import flash.display.Sprite; 
import flash.text.StyleSheet; 
import flash.text.TextField; 
import flash.text.TextFieldAutoSize; 

public class StyleSheetExample extends Sprite { 

    public function StyleSheetExample() { 
     var style:StyleSheet = new StyleSheet(); 

     var heading:Object = new Object(); 
     heading.fontWeight = "bold"; 
     heading.color = "#FF0000"; 

     var body:Object = new Object(); 
     body.fontStyle = "italic"; 

     style.setStyle(".heading", heading); 
     style.setStyle("body", body); 

     var label:TextField = new TextField(); 
     label.styleSheet = style; 
     label.htmlText = "<body><span class='heading'>Hello </span>World...</body>"; 
     addChild(label); 
    } 
    } 
} 
関連する問題