1 Reply Latest reply on Dec 12, 2010 11:08 AM by Shongrunden

    Play a sound during a state transition

    PierreSolutions Level 2

      Greetings,

       

      I would like to associate a sound with a transition so that it is played during the duration of the transition.

      What is the best way to do that in flex Hero?

       

      Thank you.

        • 1. Re: Play a sound during a state transition
          Shongrunden Adobe Employee

          You might find the SoundEffect class useful, for example:

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

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

                    xmlns:mx="library://ns.adobe.com/flex/mx"

                    title="Sound Effect">

                    

               <s:states>

                    <s:State name="state1"/>

                    <s:State name="state2"/>

               </s:states>

               

               <s:actionContent>

                    <s:Button label="toggle state" click="currentState=currentState=='state1'?'state2':'state1'" />

               </s:actionContent>

               

               <s:transitions>

                    <s:Transition fromState="*" toState="*">

                         <s:Parallel>

                              <s:Parallel target="{target}">

                                   <s:Fade />

                                   <mx:SoundEffect duration="1000" source="mySound.mp3"/>

                              </s:Parallel>

                         </s:Parallel>

                    </s:Transition>

               </s:transitions>

           

               <s:Button id="target" label="target" width="100" height="100" verticalCenter="0" horizontalCenter="0"

                           alpha.state1="1" alpha.state2="0.5"/>

               

          </s:View>