4 Replies Latest reply on Nov 15, 2010 2:34 AM by daslicht

    'Animating' variables ? Crossfading Soundcontext

    daslicht Level 2

      Hello,

      I know hoa to use the Spark Animate, but to use it you need to specify a target object and a property.

       

      But how to I animate for example a Number or another variable e.g: a Integer?

       

       

      I like to crossfade the Volume of two Soundchannels.

        • 1. Re: 'Animating' variables ? Crossfading Soundcontext
          Shongrunden Adobe Employee

          I'm not sure I understand, I'm guessing you want to animate a property on your application?  If so here's an example:

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark">

              <fx:Script>
                  <![CDATA[
                      [Bindable] public var myNumber:Number = 0;
                  ]]>
              </fx:Script>
             
              <fx:Declarations>
                  <s:Animate id="myAnimate" target="{this}" duration="5000">
                      <s:motionPaths>
                          <s:SimpleMotionPath property="myNumber" valueBy="0.1" valueFrom="0" valueTo="100" />
                      </s:motionPaths>
                  </s:Animate>
              </fx:Declarations>
             
              <s:controlBarContent>
                  <s:Button label="animate number" click="myAnimate.play()"/>
              </s:controlBarContent>
             
              <s:Label text="{myNumber}" />
             
          </s:Application>

           

          Using valueBy works nicely for integers and numbers, but if you need more control over that you can look into creating a custom interpolator.  See this post for an example: http://forums.adobe.com/message/3140616#3140616

          • 2. Re: 'Animating' variables ? Crossfading Soundcontext
            daslicht Level 2

            Thank you very much!

            Do you know how I can call a function while the number is changing ?

             

            I try it with help of a Timer and post be results later.

             

            Thank you again for your time!

            Marc

            • 3. Re: 'Animating' variables ? Crossfading Soundcontext
              Shongrunden Adobe Employee

              You could create getter/setter methods for the variable:

               

              <?xml version="1.0" encoding="utf-8"?>

              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                             xmlns:s="library://ns.adobe.com/flex/spark">

               

                  <fx:Script>

                      <![CDATA[

                          [Bindable] private var _myNumber:Number = 0;

               

                          [Bindable]

                          public function set myNumber(value:Number):void {

                              // set the number

                              _myNumber = value;

               

                              // call some function

                              myFunction();

                          }

               

                          public function get myNumber():Number {

                              return _myNumber;

                          }

               

                          private function myFunction():void {

                              trace("function called");

                          }

                      ]]>

                  </fx:Script>

               

                  <fx:Declarations>

                      <s:Animate id="myAnimate" target="{this}" duration="5000">

                          <s:motionPaths>

                              <s:SimpleMotionPath property="myNumber" valueBy="0.1" valueFrom="0" valueTo="100" />

                          </s:motionPaths>

                      </s:Animate>

                  </fx:Declarations>

               

                  <s:controlBarContent>

                      <s:Button label="animate number" click="myAnimate.play()"/>

                  </s:controlBarContent>

               

                  <s:Label text="{myNumber}" />

               

              </s:Application>

              1 person found this helpful
              • 4. Re: 'Animating' variables ? Crossfading Soundcontext
                daslicht Level 2

                Hello,

                I found the error why the property animation was not working.

                 

                My variable to animate was set to private

                 

                Thank you very much for taling time !

                 

                Here is  y anti-leak test Flex shoutcast player :

                 

                http://wensauer.info/flex/ShoutcastPlayer/ShoutcastPlayer.html