2 Replies Latest reply on Sep 7, 2010 12:58 PM by SiHoop

    AHow to apply a style

    SiHoop Level 1

      How do I apply a style in actionScript? For example, in the code below, how do I apply one of the two embedded css styles to each of the dynamically generated button?

       

      Thank you!

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  creationComplete="init()">
          <mx:Script>
              <![CDATA[           
                  import mx.controls.Button;
                  private var button:Button;
                  [Bindable] private var thisButtonNumber:Number
                  private function init():void{
                      for(var i:int=0;i<10;i++){
                          button=new Button;
                          button.width=200;
                          button.label=String(i)
                          panel.addChild(button);
                      }
              }
              ]]>
          </mx:Script>
          <mx:Style>
              .button {
                  fontSize: 18pt;
                  color: Red;
              }
              .buttonStyle1 {
                  fontSize: 12pt;
                  color: Green;
              }
          </mx:Style>
              <mx:Panel   id="panel"  />
      </mx:Application>

        • 1. Re: AHow to apply a style
          ShardulSingh Level 3

          Hi,

          Try like this:-

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  creationComplete="init()">
              <mx:Script>
                  <![CDATA[          
                      import mx.controls.Button;
                      private var button:Button;
                      [Bindable] private var thisButtonNumber:Number
                      private function init():void{
                          for(var i:int=0;i<10;i++){
                              button=new Button;
                              button.width=200;
                              button.label=String(i)
                              button.setStyle('styleName','buttonStyle'+i.toString());
                              panel.addChild(button);
                          }
                  }
                  ]]>
              </mx:Script>
              <mx:Style>
                 
                  .buttonStyle0 {
                      fontSize: 12pt;
                      color: Green;
                  }
                  .buttonStyle1 {
                      fontSize: 14pt;
                      color: Red;
                  }
                  .buttonStyle2 {
                      fontSize: 16pt;
                      color: White;
                  }
                  .buttonStyle3 {
                      fontSize: 18pt;
                      color: Yellow;
                  }
                  .buttonStyle4 {
                      fontSize: 20pt;
                      color: Green;
                  }
                  .buttonStyle5 {
                      fontSize: 22pt;
                      color: Purpole;
                  }
                  .buttonStyle6 {
                      fontSize: 24pt;
                      color: Cyan;
                  }
                  .buttonStyle7 {
                      fontSize: 26pt;
                      color: Orange;
                  }
                  .buttonStyle8 {
                      fontSize: 28pt;
                      color: Blue;
                  }
                  .buttonStyle9 {
                      fontSize: 30pt;
                      color: Black;
                  }
              </mx:Style>
                  <mx:Panel   id="panel" />
          </mx:Application>

           

           

           

           

           

           

           

           

           

           

           

          with Regards,

           

          Shardul Singh Bartwal

          • 2. Re: AHow to apply a style
            SiHoop Level 1

            Fantastic-- thank you!