Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:51:22+00:00 2026-06-12T03:51:22+00:00

I use the following example for playing an MP3 file (I don’t need/want Open

  • 0

I use the following example for playing an MP3 file (I don’t need/want “Open” dialog):

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">

<fx:Script>
    <![CDATA[
        import flash.media.*;
        [Embed(source="assets/marseljeza.mp3")]

              [Bindable]
        public var sndCls:Class;
        public var snd:Sound = new sndCls() as Sound; 
        public var sndChannel:SoundChannel;

        public function playSound():void {
            sndChannel=snd.play();
        }   
        public function stopSound():void {
            sndChannel.stop();
        }   
    ]]>
</fx:Script>

<s:HGroup>
    <s:Button label="play" click="playSound();"/>
    <s:Button label="stop" click="stopSound();"/>
</s:HGroup>
</s:View>`

After I click on the PLAY-button, the MP3 file plays just fine, but if I click the PLAY-button again, the song starts over from the start simultaneously, and the same if I click the button three, four, five or more times. So I end up with more simultaneously “sessions” of the same song. I want disable the PLAY-button after the first click, and enable the same button again after click on STOP. How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:51:24+00:00Added an answer on June 12, 2026 at 3:51 am

    To answer your specific question, you can use the enabled property on the button. Inside your playSound() method, do this::

    public function playSound():void {
        sndChannel=snd.play();
        playButton.enabled = false;
    }   
    

    Be sure to add an Id to your playButton:

    <s:Button id="playButton" label="play" click="playSound();"/>
    

    You may want to consider just adding a check inside your playSound() method to not play the sound if it is already playing. To do this, first create a variable:

    protected var isPlaying : Boolean = false;
    

    Then tweak the playButton() method like this:

    public function playSound():void {
       if(!isPlaying){
        sndChannel=snd.play();
        isPlaying = true;
       }
    }   
    

    In either of the above situations, you’ll probably want to add an event listener to the complete event in order to re-enable to button or change the isPlaying flag. The approach would be something like this:

    public function playSound():void {
       if(!isPlaying){
        snd.addEventListener(Event.COMPLETE,onSoundComplete);
        sndChannel=snd.play();
        isPlaying = true;
       }
    }   
    
    public function onSoundComplete(event:Event):void{
      isPlaying = false;
      playButton.enabled = true;
      snd.removeEventListener(Event.COMPLETE,onSoundComplete);
    }
    

    You can also call the onSoundComplete method from your stop sound method:

        public function stopSound():void {
            sndChannel.stop();
            onSoundComplete(new Event());
        }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use rb_require with rb_protect, as in the following example: int error;
Trying to use the following demo example, using the 80px x 80px snap to
for example i use following command to find a record SELECT `users`.`mail` FROM `users`
In the following example, MySQL fails to use to find a ref for the
In the following example, I tried to use uninterpreted Boolean function like (declare-const p
I'm following an example on how to use require.js and backbone.js . In the
I use the following function to rename thumbnails. For example, if I upload a
Take the following article for example: http://weblogs.asp.net/psteele/archive/2009/11/23/use-dependency-injection-to-simplify-application-settings.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+dotnetmvp+%28Patrick+Steele%27s+.NET+Blog%29 I don't see what benefit there is
Using the following code: use LWP::Simple; my $url= http://example.com; my $html= get $url; I
I am playing with the modal forms available with jQueryTools. I want to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.