1 Reply Latest reply on Dec 6, 2010 1:09 AM by BhaskerChari

    Setting style for Text control in flex

    rizmysl

      hi,

       

      i wanted set style for Text control in flash i tryed below and but doesn't work any idea please

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
           <mx:Style>
                .texfield{ width:300; height:30; background-color:red; fontWeight:bold;}
           </mx:Style>
           
           <mx:Label x="25" y="113" text="My Sample Text Goes Here ...."  styleName="texfield" id="tetxfield" />
           
      </mx:Application>
      
      
        • 1. Re: Setting style for Text control in flex
          BhaskerChari Level 4

          Hi rizmysl,

           

          You cannot directly set the backgroundColor to a Label control however you can do it by getting a reference to the underlying TextField control inside the Label, for that you need to write some actionscript.

           

          Check out the below code:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
               <mx:Style>
                    .texfield{ width:300; height:30; background-color:red; fontWeight:bold;}
               </mx:Style>
               <mx:Script>
                <![CDATA[
                 import mx.core.IUITextField;
                
                 private function init():void
                 {
                  //Getting reference to the underlying TextFiled control inside Label
                  var tf:IUITextField = (myTextField.mx_internal::getTextField());
                  tf.background = true;
                  tf.backgroundColor = 0XFF0000;
                  tf.width = 300;
                  tf.height = 30;
                 }
                
                ]]>
               </mx:Script>
              
               <mx:Label x="25" y="113" text="My Sample Text Goes Here ...."  styleName="texfield" id="myTextField" />
              
          </mx:Application>

           

           

           

          Thanks,

          Bhasker Chari    

          1 person found this helpful