5 Replies Latest reply on Aug 24, 2009 12:28 PM by sandc666-YGfr5p

    Calling a Function in a Component

    sandc666-YGfr5p

      Hi I know this is simple but I can not get this to work I ahve looked for example but come uo with nothing

       

      I want to call a function in a  Component

       

      I created  acompoinent based on a label

       

       

       

       

       

       

       

       

       

       

       

       

       

       

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

      <mx:Label

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml">

       

       

       

       

       

         <mx:Script>

           <![CDATA[

       

       

       

             public var mp3:String;

       

       

       

           private var soundChannel:SoundChannel;

       

       

       

       

      // this function will load and play the sound

       

       

          public function playSound():void{

       

       

             var urlRequest:URLRequest = new URLRequest(mp3);

       

       

            var sound:Sound = new Sound();

           sound.load(urlRequest);

       

      // will stop sound of no device is found

       

       

           if(soundChannel != null ) {

               soundChannel.stop();

            }

       

           soundChannel = sound.play();

       

         }

       

      // this function stops the sound from playing, this need tos work on the sound channel

       

       

          private function stopSound():void

           {

              soundChannel.stop();

           }

       

           ]]>

       

       

        </mx:Script>

      </mx:Label>

       

      calling looks like

       

       

       

       

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

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:uofs="uofs.*" >

       

       

       

      <uofs:ulable text="hellow" id="b21" x="200" y="300" mp3="jazz.mp3" click="playSound()" />

       

       

      </mx:Application>

       

       

      also how wolud you pass a string in the click

       

      click="playSound(jazz.mp3)"  or click="playSound("jazz.mp3")"

       

      do not work