2012-12-23 41 views
0
package { 
    import flash.text.TextField; 
    import flash.text.StyleSheet; 
    import flash.text.TextFieldAutoSize; 

    public class MyTF extends TextField { 

     public var 

     color:uint, 
     size:int 
     public function MyTF(color:uint, size:int) { 
      super(); 

      color = color; // setting color and size 
      size = size; 

      init(); //initialize 
     } 

     private function init():void 
     { 
      autoSize = TextFieldAutoSize.LEFT; 
      var style:StyleSheet = new StyleSheet(); 
      style.setStyle('span', {color: 0xFF0000, fontSize: 24}); 
      styleSheet = style; 
      htmlText = '<span>test</span>'; 

        //after creating an object of this class the text Style is not changing 
     } 

    } 

} 

爲什麼創建這個類的實例後htmlText樣式不會改變?有什麼不對?爲什麼styleSheet不起作用?

回答

0

如果我沒看錯你明白這可以幫助你:

style.setStyle('span', {color: 0xFF0000, fontSize: 24});變化 style.setStyle('span', {color: this.color, fontSize: this.size});