Whack... I so did not have that problem when I tested months ago.  Thanks 
for attaching the example!

----- Original Message ----- 
From: "Tarik Ahmed" <[EMAIL PROTECTED]>
To: <flexcoders@yahoogroups.com>
Sent: Tuesday, July 05, 2005 6:46 PM
Subject: Re: [flexcoders] embedded sounds


For fun I thought I'd test this out. The snd= new Sound(this); didn't
make a difference for me, and I am able to reproduce Tom's problem.

         [Embed('test1.mp3')]
         var soundSymbol1:String;
         [Embed('test2.mp3')]
         var soundSymbol2:String;

        function playSong()
        {
            var currentSound= songComboBox.selectedItem.value;
            startSound(currentSound);
        }

 <mx:ComboBox id="songComboBox" change="playSong()"
dataProvider="{mySamples.option}"  labelField="label"/>

Basically when you do a

startSound(beki1A);-> beki1A is = to something like 
__Resources.1387713460.beki1A_mp3

So your combo box would have to contain whatever the value of the name of 
the variable that your songComboBox.selectedItem.value is equal to. In CF 
you'd use the Evaluate function to do that,

I did a little hacking and found that this did the job:

        function playSong()
        {
            var currentSound= songComboBox.selectedItem.label;
            var playThis = eval(currentSound);
            startSound(playThis);
        }

Full working example attached (except for mp3s).




JesterXL wrote:

>Close, do:
>
>snd = new Sound(this);
>
>----- Original Message ----- 
>From: "Tom Fitzpatrick" <[EMAIL PROTECTED]>
>To: <flexcoders@yahoogroups.com>
>Sent: Tuesday, July 05, 2005 5:13 PM
>Subject: [flexcoders] embedded sounds
>
>
>I'm trying to embed a number of mp3 sounds and play them back in various
>ways.
>
>The first way is to select the sound names from a comboBox. It's not
>working.
>
>So, for an embedded sound defined as:
>
>[Embed('beki1A.mp3')]
>var beki1A:String;
>
>I've defined the following function;
>
>          var snd:Sound;
>
>function startSound(currentSound)
>{
>            snd = new Sound;
>snd.attachSound(currentSound);
>snd.start();
>}
>
>If I call this function with a button click, like this:
>
><mx:Button label="Start" id="b1" click="startSound(beki1A);" />
>
>it works fine.
>
>If I pass the value of "currentSound" from a comboBox, with the following
>function specified as the change event of the comboBox:
>
>function playSong()
>{
>var currentSound= songComboBox.selectedItem.label;
>startSound(currentSound);
>}
>
>it does not work.
>
>When I trace the value of "beki1A" in the buttonclick version, it has a
>resource prefix - and this appears to be "lost" when it's assigned to
>another variable via the comboBox. Or is it something even simpler?
>
>Where am I going wrong?
>
>- Tom
>
>
>


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links







--------------------------------------------------------------------------------


<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"; xmlns="*">
   <mx:Script>
      <![CDATA[
         var snd:Sound;
         [Embed('test1.mp3')]
         var soundSymbol1:String;
         [Embed('test2.mp3')]
         var soundSymbol2:String;

         function startSound(playme) {
            snd = new Sound;
            snd.attachSound(playme);
            snd.start();
         }

         function stopSound() {
            snd.stop();
         }

function playSong()
{
var currentSound= songComboBox.selectedItem.value;
            var playThis = eval(currentSound);
startSound(playThis);
}
      ]]>
   </mx:Script>

<mx:Model id="mySamples">
 <option value="" label=""/>
 <option value="soundSymbol1" label="soundSymbol1"/>
 <option value="soundSymbol2" label="soundSymbol2"/>
</mx:Model>

   <mx:VBox>
      <mx:Button label="Start" id="b1" click="startSound(soundSymbol2);" />
      <mx:Button label="Stop" id="b2" click="stopSound();" />
      <mx:ComboBox id="songComboBox" change="playSong()" 
dataProvider="{mySamples.option}"  labelField="label"/>

   </mx:VBox>

</mx:Application>




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to