1 Reply Latest reply on Feb 26, 2010 3:43 PM by Gregory Lafrance

    Randomly selecting the .....

    aktell2007 Level 1

      Hi there,

       

      I have a set up with an HSlider where I can select my ViewStack.

      change="viewStack.selectedIndex = event.value;"
      

      I'm looking for the 'Random' selection of the selectedIndex at StartUp to initilize my timer ???

       

      thanks in advance aktell 2007

        • 1. Re: Randomly selecting the .....
          Gregory Lafrance Level 6

          This should answer your question:

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            creationComplete="init();">
           <mx:Script>
            <![CDATA[
                private function init():void{
                  var num:Number = Math.floor(Math.random() * vs.numChildren);
                  vs.selectedIndex = num;
                  trace(num);
                }
            ]]>
           </mx:Script>
            <mx:ViewStack id="vs">
              <mx:VBox width="200" height="200" backgroundColor="0xFF0000"/>
              <mx:VBox width="200" height="200" backgroundColor="0x00FF00"/>
              <mx:VBox width="200" height="200" backgroundColor="0x0000FF"/>
              <mx:VBox width="200" height="200" backgroundColor="0x000000"/>
              <mx:VBox width="200" height="200" backgroundColor="0xCCCCCC"/>
            </mx:ViewStack>
            <mx:Button click="init();" label="Refresh"/>
          </mx:Application>
          


          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services