0 Replies Latest reply on Sep 7, 2010 7:46 AM by Phuong Thanh

    Sound on/off by click a button in flex4????

    Phuong Thanh

      hello everybody, i want to make a website by flex.in that have sound  effect. i want when i load page have sound and if i don't want to listen  i can click button.the sound will stop play and else. But i don't know  how to make on/off sound by a button click

      i done:

      in actionscript file                Sound_playExample1.as: i write code

      package myComponents {
          import flash.display.Graphics;
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.events.MouseEvent;
          import flash.events.ProgressEvent;
          import flash.media.Sound;
          import flash.media.SoundChannel;
          import flash.net.URLRequest;
          public class Sound_playExample1 extends Sprite {
                      private var snd:Sound = new Sound();
              private var channel:SoundChannel = new SoundChannel();
              public function Sound_playExample1() {           
                  var req:URLRequest = new URLRequest("myComponents/soundall.mp3");
                      channel = snd.play(0,6);   
      // ActionScript file

      in my Main.mxml:i write


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

                  protected function button1_clickHandler(event:MouseEvent):void
                      // TODO Auto-generated method stub

              <!-- Place non-visual elements (e.g., services, value objects) here -->
          <s:Button x="177" y="71" label="Button" click="button1_clickHandler(event)"/>
      can u help me please what i have to do. if you know you can

      Additional for this code.thanks