On/off sound by a button in flex

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");
            snd.load(req);              
                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:s="library://ns.adobe.com/flex/spark"
               xmlns:MyComp="myComponents.*"
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            protected function button1_clickHandler(event:MouseEvent):void
                // TODO Auto-generated method stub
        ]]>
    </fx:Script>
    <fx:Declarations>
         <MyComp:Sound_playExample1/>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button x="177" y="71" label="Button" click="button1_clickHandler(event)"/>
</s:Application>
can u help me please what i have to do. if you know you can Additional for this code.thanks

Hi,
This is complete solution of your issue.Let me know if u find and issue.
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/halo"
              creationComplete="application1_creationCompleteHandler(event)"
              >
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            private function onClick():void
                createSound();
                channel = sound.play();
            private function offClick():void
                if(channel != null)
                    channel.stop();
            private var sound:Sound;
            private var channel:SoundChannel = new SoundChannel();
            protected function application1_creationCompleteHandler(event:FlexEvent):void
                isPlaying = false;
                onOff();
            private function createSound() : void
                var req:URLRequest = new URLRequest("assets/audio1.mp3");
                if(channel != null)
                    channel.stop();
                if(sound != null)
                    sound = null;
                sound = new Sound();
                sound.load(req);
            [Bindable]
            private var isPlaying : Boolean;
            protected function onOff():void
                if(isPlaying == false)
                    onClick();
                    isPlaying = true;
                    return;
                else
                    offClick();
                    isPlaying = false;
        ]]>
    </fx:Script>
    <s:HGroup>
        <s:Button label="{isPlaying == false? 'ON' : 'OFF'}" click="onOff()"/>
    </s:HGroup>
</s:Application>
with Regards,
Shardul Singh Bartwal

Similar Messages

  • On/off sound in a button in flex4

    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");
                snd.load(req);              
                    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:s="library://ns.adobe.com/flex/spark"
                   xmlns:MyComp="myComponents.*"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
        <fx:Script>
            <![CDATA[
                protected function button1_clickHandler(event:MouseEvent):void
                    // TODO Auto-generated method stub
            ]]>
        </fx:Script>
        <fx:Declarations>
             <MyComp:Sound_playExample1/>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <s:Button x="177" y="71" label="Button" click="button1_clickHandler(event)"/>
    </s:Application>
    can u help me please what i have to do. if you know you can
    Additional for this code.thanks

    // below code sinppet should go into on button click event handle method.
    if
    (pausePosition==0 ){ if(channel!=null){pausePosition = channel.position;
    channel.stop();
    sound.setStyle("icon",soundOffClass);  // mute
    }else{ 
    if(channel!=null){channel.stop();
    channel = snd.play(pausePosition);
    sound.setStyle("icon",soundOnClass); // un mute , this should be default as
    pausePosition=0;

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

    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");
                snd.load(req);              
                    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:s="library://ns.adobe.com/flex/spark"
                   xmlns:MyComp="myComponents.*"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
        <fx:Script>
            <![CDATA[
                protected function button1_clickHandler(event:MouseEvent):void
                    // TODO Auto-generated method stub
            ]]>
        </fx:Script>
        <fx:Declarations>
             <MyComp:Sound_playExample1/>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <s:Button x="177" y="71" label="Button" click="button1_clickHandler(event)"/>
    </s:Application>
    can u help me please what i have to do. if you know you can
    Additional for this code.thanks

    // below code sinppet should go into on button click event handle method.
    if
    (pausePosition==0 ){ if(channel!=null){pausePosition = channel.position;
    channel.stop();
    sound.setStyle("icon",soundOffClass);  // mute
    }else{ 
    if(channel!=null){channel.stop();
    channel = snd.play(pausePosition);
    sound.setStyle("icon",soundOnClass); // un mute , this should be default as
    pausePosition=0;

  • I want to know how to clear the text area by the push off my next question button and ask a new ques

    I want to know how to clear the text area by the push off my next question button and ask a new question - also I want to know how to code in my project to where a user can enter a math question in one border container and the answer enters into the next container
    heres my code so far
    <?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"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" backgroundColor="#1E5C75">
        <fx:Script>
            <![CDATA[
                protected function button1_clickHandler(event:MouseEvent):void
                    //convert text area into labelid to be identified by actionscript
                    richTextLabel.text = myArea.text;
            ]]>
        </fx:Script>
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <!--container 1-->
        <s:BorderContainer borderWeight="7" x="28" y="10" width="200" height="138">
            <s:layout>
                <s:VerticalLayout paddingTop="10" paddingBottom="10"
                                  paddingLeft="10" paddingRight="10"/>
            </s:layout>
            <!--data Entry control-->
            <s:TextArea id="myArea" width="153" height="68"/>
            <!--end of data entry control-->
            <s:Button width="151" label="ask a question" click="button1_clickHandler(event)"/>
        </s:BorderContainer>
        <!--container2-->
        <s:BorderContainer borderWeight="7" x="509" y="10" width="200" height="138">
            <s:layout>
                <s:VerticalLayout paddingTop="10" paddingBottom="10"
                                  paddingLeft="10" paddingRight="10"/>
            </s:layout>
    <!--data entry control-->
            <!--convert tne data entry control into a label id in actionscript-->
            <s:Label id="richTextLabel" width="153" height="68"/>
            <s:Button width="151" label="next question" click="button1_clickHandler(event)"/>
        </s:BorderContainer>
        </s:Application>

    This is a user to user support forum.  We are all iphone users just like you.
    You are not addressing Apple here at all.
    This is an odd way to ask your fellow iphone users for help. Berating oterh users will not help you.
    "it's too fragile"
    No it is not.  i have never damaged one, nor has anyone I know.
    " U loose data when Ur phone is locked"
    No you don't.  Why do you think this?
    "and there is no customer support!!!  "
    Wrong yet again.  Apple has an 800 number and they have many retail stores and they have support articles that you can access using the search bar. Or you can contact them throgh express lane online
    "but I will go back with Blackberry "
    Please do.
    Good ridance

  • Every time I unmute my iPad, the sound efx does not come back. I can hear my keypad and the on/off sounds but no app sounds.

    Every time I unmute my iPad, the sound efx does not come back. I can hear my keypad and the on/off sounds but I can't here the sounds from deleting photos, clicking on apps that are on my iPad. It does this every time I unmute my iPad. Please advise.

    Hello PearldiamondMD,
    I was thinking of a few recommendations for you. I recommend our iPhone Troubleshooting Assistant found here http://www.apple.com/support/iphone/assistant/phone/#section_1. Start at section 1, if that doesnt fix it, then section 3, and if all else does not work, section 5. At section 3 I recommend closing ALL the apps.
    Here is section 1 to get you started.
    Restart iPhone
    To restart iPhone, first turn iPhone off by pressing and holding the Sleep/Wake button until a red slider appears. Slide your finger across the slider and iPhone will turn off after a few moments.
    Next, turn iPhone on by pressing and holding the Sleep/Wake button until the Apple logo appears.
    Is iPhone not responding? To reset iPhone, press and hold the Sleep/Wake button and the Home button at the same time for at least 10 seconds, until the Apple logo appears.
    If your device does not turn on or displays a red battery icon, try recharging next.
    All the very best,
    Sterling

  • Sound and brightness buttons dont work anymore

    my sound and brightness buttons dont work any more unless I hold down the function button. This happened after I downloaded the new update I think. Is there any key combination that I could have hit that made this happen?

    Go to System Preferences->KeyBoard & Mouse->KeyBoard and make sure "Use the F1-F12 keys to control software featues" is off. It probably got turned on somehow by the update.

  • Will not:  rotate screen, camera will not work, iPad will not turn off, sound on side.

    Ipad will not turn off, sound button does not work, camera does not work,  screen will not rotate.  Have new ios and update.

    Reset all settings
    Settings>General>Reset>Reset All Settings
    Note: Data will not be affected but settings will be reset.

  • Sound On / Of Button

    Hello
    I found this tutorial where they teach you to add a sound on
    of button
    TUTORIAL
    But as you can see there is no ON or OFF button here.. I
    tried adding the symbols On and Off seperatly. But with the action
    script i got a bit mixed up and at one point of the movie both the
    labels are visibile at the same time..
    My
    movie
    sound_btn_on._alpha = 0;
    var mySound:Sound = new Sound();
    mySound.attachSound("myTrack");
    mySound.start();
    var soundStarted:Boolean = true;
    sound_btn_off.onRelease = function() {
    soundStarted = !soundStarted;
    if (soundStarted) {
    this._alpha = 100;
    mySound.start();
    } else {
    this._alpha = 0;
    mySound.stop();
    sound_btn_on._alpha = 100;
    sound_btn_on.onRelease = function() {
    soundStarted = !soundStarted;
    if (soundStarted) {
    this._alpha = 0;
    mySound.start();
    sound_btn_off._alpha = 100;
    } else {
    this._alpha = 0;
    mySound.stop();
    Any idea??
    Thank you.

    > sound_btn_on._alpha = 0;
    > var mySound:Sound = new Sound();
    > mySound.attachSound("myTrack");
    > mySound.start();
    > var soundStarted:Boolean = true;
    > sound_btn_off.onRelease = function() {
    > soundStarted = !soundStarted;
    > if (soundStarted) {
    > this._alpha = 100;
    ONOFF.gotoAndStop(2);
    > mySound.start();
    > } else {
    > this._alpha = 0;
    ONOFF.gotoAndStop(1);
    > mySound.stop();
    > sound_btn_on._alpha = 100;
    > }
    > };
    >
    make a movie clip ONOFF and on frame 1 place the OFF button
    look
    and stop action, on frame the the ON button look and the
    stop(); action.
    Then simply add what's above....
    Best Regards
    Urami
    "Never play Leap-Frog with a Unicorn."
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • Hi I have a MacBook Pro 2011 i7 and it stays on for about 4 hours then the screen go's fuzzy and I have to turn it off by the power button has anyone had this problem thanks mike

    I Have a MacBook Pro i7 2011 it stays on for about 4 hours then the screen go's all fuzzy and I have to turn it off by the power button has any body else had this problem thanks mike

    My guess would also be a failling connection between your logicboard and your GPU. See 2011 MacBook Pro and Discrete Graphics Card
    For most users it starts with some random crashes and freezes like you describe it. And then it just gets worse and worse. There are still no "good" solutions, sadly. This is a hardware problem from the production.

  • So I have an iPad with the smart cover, and it's usually supposed to turn on the iPad when u open it, but it's no doing that for me. Nor is it turning off without pressing the button. What is the meaning of this?

    So I have an iPad with the smart cover, and it's usually supposed to turn on and off the iPad when u open it and close it, but it's not turning on for me. Nor is it turning off without pressing the button. What is the meaning of this?what caused it to be this way? Is there someway that I could fix it?

    Wait a sec did this just start?
    You set up the smart cover function in settings (you did that, right?) so, if you did that and it's failed you make an appointment at your nearest Genius Bar now.

  • Where in gods name is the homesharing button, I see a little cloud that you cannot click on and tells you what account you have but thats is. There's an option for turning on and off homesharing, but no button to access the actual library of the other PC

    Where in god’s name is the homesharing button, I see a little cloud that you cannot click on and tells you what account you have but that's it. There's an option for turning on and off homesharing, but no button to access the actual library of the other PC. On either PCs. Both are logged in and both are registered for homesharing. however because apple keeps updating and moving things around for no reason there appears to be no way of accessing the homsharing button in the latest version of itunes. the website refers to " Once set up, all the libraries from your computers you've enabled Home Sharing on will show up in the SHARED area of iTunes:" well I have searched all over in the recent itunes versions and there is no "shared area" to be found.
    Please find the attachment of a screen cap of my itunes.
    If anyone can help by telling me where it has been moved to or if it even still exists that would be much appreciated.

    Welcome to the Apple Community.

  • My iphone 4s' screen is black, but it's still on and charging. I broke my lock screen button so I am unable to turn it off using the home button and lock button. Is there any other way my phone can restart or turn off ? Is my phone broken for sure?

    My iphone 4s' screen is black, but it's still on and charging. I broke my lock screen button so I am unable to turn it off using the home button and lock button. Is there any other way my phone can restart or turn off ? Is my phone broken for sure?

    Kbkohn wrote:
    I am in tears right now because I entered all my 11month old sons milestones into my phone and now I have nothing I'm so upset and am hoping there is a way to get this information back. 
    Most intelligent people would not store such sensitive data on a device that could so easily be lost, stolen, or damaged.  Even if they chose to do so, they would use the device as designed and regularly sync and backup that device as described in the User's Guide.
    Have you done so?  If you have, all of the data is either in iCloud or iTunes on your computer.  Replace the device and restore the new iDevice with the backup of the old one.

  • How do you make a gradient background on a button in flex 4

    Hey everyone, this is driving me crazy. Below is my css for a button in file.  I want a gradient background on a button in flex 4. I can not for the life of me figure out how to do this. There is no longer the backgroundColors option. chromeColor is only a single color and all the examples I see on the web using fill, and linearGradient throw up errors so I assume these were only in the beta? This is very frustrating to not be able to do a simple thing in flex 4 that worked in flex 3. Any ideas? Thanks.
    Button {
    cornerRadius: 3;
    highlightAlphas: 0.36, 0;
    fillAlphas: 1, 1, 1, 1;
    paddingLeft: 5;
    paddingRight: 5;
    backgroundColors: #ff6600, #ff9900, #ffffff, #eeeeee;
    color: #ffffff;
    disabledColor: black;
    textRollOverColor: #000000;
    textSelectedColor: #000000;
    borderColor: #ff6600;
    fontWeight: normal;

    This may not be what you're looking for, but since you are stuck, I'll elaborate on what FTQuest was saying. It will only take a few minutes to do this.
    In FB4:
    1. right-click the button, choose "Create Skin", give it a package (directory) and name (filename), host component "spark.components.Button" and "Create as copy of" "spark.skins.spark.ButtonSkin".
    This creates junk.mxml for you, the skin file.
    2. In the source of junk.mxml, change layer 1 (shadow) and layer 2 (fill) colors as I did here in this code. Note that where you see {color#}, this is data-binding to a variable I've made in a color.as file that I've included in the skin file. In fact, that is ALL that I changed in the skin file it generated for me.
    snippet from colors.as:
    public   var color1:int = new int(0xA1D190);
    snippet from junk.mxml:
    <![CDATA[
    include "Colors.as";
    layer changes in junk.mxml:
    <!-- layer 1: shadow -->
    <!--- @private -->
    <s:Rect id="shadow" left="-1" right="-1" top="-1" bottom="-1" radiusX="2">
    <s:fill>
    <s:LinearGradient rotation="90">
    <s:GradientEntry color="0x000000" color.down="
    {color5}"alpha="
    0.01"alpha.down="
    0" />
    <s:GradientEntry color="0x000000" color.down="
    {color6}" alpha="
    0.07"alpha.down="
    0.5" />
    </s:LinearGradient>
    </s:fill>
    </s:Rect>
    <!-- layer 2: fill -->
    <!--- @private -->
    <s:Rect id="fill" left="1" right="1" top="1" bottom="1" radiusX="2">
    <s:fill>
    <s:LinearGradient rotation="90">
    <s:GradientEntry color="{color2}" color.over="
    {color3}" color.down="
    {color4}" alpha="
    0.85" />
    <s:GradientEntry color="{color4}" color.over="
    {color5}" color.down="
    {color6}" alpha="
    0.85" />
    </s:LinearGradient>
    </s:fill>
    </s:Rect>
    You can (and maybe should) hardcode colors in here to do your gradients. After this, your button will need to use the skin, like:
    <s:Button ... skinClass="Skins.junk">
    ... where "Skins" is the name of the package/directory I told it to create the skin in.
    This may not be ideal for you, but it's working for me. Regarding having variables for color values, I posted a thread this morning asking if this is the best way to do things or not, so I don't know if it's the way to go.
    Hope this helps ... 

  • Multiple sounds in one button

    would you kindly give me a suggestion that how to make multiple sounds in a button of a windows form application. actually, being a newb i'm trying to develop a piano application by C# for my own interest. the problem is, when i press one button it plays
    too long & i had to wait until the wav file is finished & after that i had to press another button. what's the code for playing multiple sounds together in one button? u know, then i can play chords too. would you kindly explain or give a code?

    Hi Rinku,
    This is an example for you:
    A Piano Key Control in C#
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Grey screen with message "turn off computer with power button until switch off then press again power button"

    Dear all,
    I'm very hungry with my iMac and my Time Capsule :
    I try for two weeks to restore my iMac without any success...
    I wait 80 hours to finally have the message again and again : "to restart your computer : turn off computer with power button until switch off then press again power button".
    But my iMac do not work !
    Could you help me?

    Hello, that's a kernel panic...
    http://thexlab.com/faqs/kernelpanics.html
    Could be many things, we should start with this...
    "Try Disk Utility
    1. Insert the Mac OS X 10.6 Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)
    If perchance you can't find your install Disc, at least try it from the Safe Boot part onward.

Maybe you are looking for

  • Why won't my vi run outside of the LV2011 project explorer?

    I've created a LV2011 project. The vi's within this project open executables to perform measurement functions. When I open the vi's from within the project explorer window the executables open with no issues. However, with the LV project closed and o

  • OSX LION BUGS I HAVE NOTICED

    Hi everybody! Since Lion is out for some time already and all upgrades so far did not fix any of the bugs I am having I decided to make a list of things that are REALLY bothering me. 1.) QUICKLOOK -> when viewing a PDF and pressing the full screen bu

  • Effectively Marking a form for a client signature

    I work in the financial services business and use acrobat to create and fill out forms for clients.  Some of the forms we use are not suitable for digital signatures.  We have to fill them out and mail to a client for signature.  I have two questions

  • Just downloaded logic 8.1 update from my auto updates and its done damage

    Hey guys im pretty sure the update was a 8.1 or 8.0.1. whatever it was its done some kind of damage because when i play back arrangements that i had previously not had problems with the cpu usage goes into the red on the right side and the audio is c

  • Webcam Driver for Dell xps 1530 notebook

    How can i identify the type of webcam installed in my notebook. I'm looking for actual windows 7 drivers for the webcam. Unfortunately on the dell support-site?there is no information available. Thanks