1 Reply Latest reply on Jun 7, 2008 2:16 PM by Gregory Lafrance

    Changing the background with timer?

    Shelady
      Hi,
      In my project, the background of the application is black and red gradient. I want to change it yellow and black and then green and black after every 30 seconds?
      Any idea?
      Thanks.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical"
      backgroundGradientColors="[#000000, #660707]" backgroundGradientAlphas="[1.0, 1.0]" verticalScrollPolicy="off">

      <mx:Style>

      VBox {
      borderColor: #000000;
      borderStyle: outset;
      border-thickness: 2;
      }

      </mx:Style>



      <mx:Accordion id="myAccordion" width="600">

      <mx:VBox id="ms" label="Microsoft" width="100%" height="500" horizontalScrollPolicy="off">
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:HBox horizontalScrollPolicy="off">
      <mx:Image source="assets/microsoft4SBTH.jpg" height="80" width="80"/>
      </mx:HBox>
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:Text text="Microsoft is the best in wondows. Yes they are really good and getting better each and {'\n'}every day. They have introduce Windows 7 and launcing the exams too." width="100%"/>
      </mx:HBox>
      </mx:HBox>
      </mx:VBox>

      <mx:VBox id="cs" label="Cisco" width="100%" height="500" horizontalScrollPolicy="off">
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:HBox>
      <mx:Image source="assets/c.jpg" height="80" width="80"/>
      </mx:HBox>
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:Text text="Microsoft is the best in wondows. Yes they are really good and getting better each and every day. They have introduce Windows 7 and launcing the exams too." width="100%"/>
      </mx:HBox>
      </mx:HBox>
      </mx:VBox>

      <mx:VBox id="st" label="Symantec" width="100%" height="500" horizontalScrollPolicy="off">
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:HBox>
      <mx:Image source="assets/Symantec.jpg" height="80" width="80"/>
      </mx:HBox>
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:Text text="Microsoft is the best in wondows. Yes they are really good and getting better each and every day.{'\n'} They have introduce Windows 7 and launcing the exams too." width="100%"/>
      </mx:HBox>
      </mx:HBox>
      </mx:VBox>

      <mx:VBox id="vm" label="VMWare" width="100%" height="500" horizontalScrollPolicy="off">
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:HBox>
      <mx:Image source="assets/vmware4SBTH.jpg" height="80" width="80"/>
      </mx:HBox>
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:Text text="Microsoft is the best in wondows. Yes they are really good and getting better each and every day. {'\n'}They have introduce Windows 7 and launcing the exams too." width="100%"/>
      </mx:HBox>
      </mx:HBox>
      </mx:VBox>

      <mx:VBox id="ct" label="Citrix" width="100%" height="500" horizontalScrollPolicy="off">
      <mx:HBox horizontalScrollPolicy="off" width="100%">
      <mx:HBox>
      <mx:Image source="assets/Citrix_Logo.jpg" height="80" width="80"/>
      </mx:HBox>
      <mx:HBox horizontalScrollPolicy="off">
      <mx:Text text="Microsoft is the best in wondows. Yes they are really good and getting better each and every day. {'\n'}They have introduce Windows 7 and launcing the exams too." width="100%"/>
      </mx:HBox>
      </mx:HBox>
      </mx:VBox>
      </mx:Accordion>

      </mx:Application>
        • 1. Re: Changing the background with timer?
          Gregory Lafrance Level 6
          This works, though if you want three color changes you'll have to change the if else logic. You also need to change the colors as desired:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          backgroundGradientColors="[#000000, #660707]"
          backgroundGradientAlphas="[1.0, 1.0]" creationComplete="init()">
          <mx:Script>
          <![CDATA[
          private var tm:Timer = new Timer(30000, 0);
          private var cnt:uint = 0;

          private function init():void{
          tm.addEventListener(TimerEvent.TIMER, onTick);
          tm.start();
          }

          private function onTick(e:TimerEvent):void{
          var arr:Array;
          cnt++;
          if(cnt % 2 == 0){
          arr = [0x000000, 0xccffcc];
          setStyle("backgroundGradientColors",arr);
          }else {
          arr = [0x000000, 0x660707];
          setStyle("backgroundGradientColors", arr);
          }
          }
          ]]>
          </mx:Script>
          </mx:Application>