dcsimg
A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Beginner Question: Show/Hide a button To Stop/Play Sound

  1. #1
    Member
    Join Date
    Apr 2002
    Posts
    39

    Beginner Question: Show/Hide a button To Stop/Play Sound

    Hello,
    I would like a movie clip in my site to either stop or play the background sound. This movie clip is visible by default on a frame. When I click the movie clip I would like it to disappear, stop the sound and be replaced by another movie clip to play the sound again.

    In the stop sound movie clip I wrote:
    on (release) {
    stopAllSounds;
    stop._visible = false;
    play._visible = true;
    }
    But it does not work...

    And what should I write in the play sound MC?

    Thank you for your time.

    Cheers

  2. #2
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Attach your .fla.

  3. #3
    Member
    Join Date
    Apr 2002
    Posts
    39
    I tried to upload it but it is too big with the sound :-( Don't know what I can do...
    Last edited by maflu; 04-27-2003 at 01:23 PM.

  4. #4
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,490
    Is that the exact code you used? I can see a couple problems with it right off. Line 3 should be stopAllSounds();. And if you named buttons 'stop' and 'play', that's not going to work. Those are flash keywords, you can't use them for instance names.

  5. #5
    Member
    Join Date
    Apr 2002
    Posts
    39
    OK I changed the code to read:
    on (release) {
    stopAllSounds();
    stop_soundMC._visible = false;
    play_soundMC._visible = true;
    }

    There is a progress because when I click on the movie clip the sound stops playing now. But the rest still does not work.

  6. #6
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Hard headed aren't you!

  7. #7
    Member
    Join Date
    Apr 2002
    Posts
    39
    Why please???

  8. #8
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,490
    Name the movieclips something else.

  9. #9
    Member
    Join Date
    Apr 2002
    Posts
    39
    But I did since "play" is now named "play_soundMC" and "stop" is now "stop_soundMC".

  10. #10
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,490
    And it's not working. Rename them mc1 and mc2 and try this code:

    on (release) {
    stopAllSounds();
    _root.mc1._visible = false;
    _root.mc2._visible = true;
    }

  11. #11
    Member
    Join Date
    Apr 2002
    Posts
    39
    Thank you. It is working now. The reason why it was not working is that I had forgotten the "_root" part of the statement.

    WIth the 2 MCs (play and stop) now I am trying to hide the stop MC when the user clicks on it and the sound stop and the play MC shows at the same time. And I would like to have the contrary behavior with the play MC.

    Not an easy task for a beginner... I can now hide the stop MC and stop the sound and show the play MC. But I am stuck there... Each MC is on a separate layer.

  12. #12
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,490
    Your making my hair stand on end by naming movie clips stop and play. Those are flash keywords, and in the end are going to cause you trouble.

    So, are you using buttons to control these movie clips? It seems you are. Then just reverse the code. On the button to start the sound, add the code to make one mc visible and the other not.

  13. #13
    Member
    Join Date
    Apr 2002
    Posts
    39
    No, I do not use the words stop and play to name my MCs. I just call them so here because I find it easier but I named them differently.

    Actually I am not using buttons. I created 2 MCs (one to stop the sound and one to play the sound) and put them on the stage in 2 different layers.

    In the stop MC (which is to appear as the default) I put:
    onClipEvent (load) {
    _root.play_soundMC._visible = false;
    _root.play_soundMC.removeMovieClip();
    }
    onClipEvent (mouseDown) {
    stopAllSounds();
    _root.stop_soundMC._visible = false;
    _root.play_soundMC._visible = true;
    }

    When I click on the stop MC, the sound stops, the stop MC disappears but nothing appears... and I am stuck there...

    Thanks a lot for your time.

  14. #14
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    I repeat once again, you are hard headed aren't you! You won't attach your .fla(s) and furthermore you don't give us the "correct" info, grant you on clip names, but what other important info have you held back? This problem might of been long solved, if you had simply attached your .fla(s)!

  15. #15
    Member
    Join Date
    Apr 2002
    Posts
    39
    Really I wonder if you are not more hard-headed than myself: you should take your time and read my posts carefully. If you had done so you would have noticed that:
    - I already tried to attach my fla file but it was rejected as too big.
    - I have given you the correct info from the beginning and by the way what's my interest in retaining info I ask you?

    I hate personnal attack. So please oldnewbie if you are not ready to help me there is no need for you to intervene and attack me personnaly.

  16. #16
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    I'm not attacking you... Guess that's your perception of all of this! Or my choice of words since English is not my mother language.

    There are ways around too big sizes of attached .flas! You can try to zip them up, which often does it, or if the zip is still too large, you can either upload it to your server and provide a link to download it from there. You can also e-mail it to the person that's willing to try and help you out, as I have from the beginning!

    If the hat fits, wear it!

  17. #17
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,490
    If your using movie clips for buttons, and you press on them, then don't use mouseDown, use press or release. Try it this way:

    Put this in the first frame:

    _root.play_soundMC._visible = false;

    Put this in a frame, to control the stop mc button:

    _root.stop_soundMC.onPress = function(){
    stopAllSounds();
    _root.play_soundMC._visible = true;
    }

    _root.stop_soundMC.onRelease = function(){
    _root.stop_soundMC._visible = false;
    }

    Put this in the same frame to contol the play mc:

    _root.play_soundMC.onPress = function(){
    //this is where the attachSound or whatever code you use to play the sound goes.
    _root.stop_soundMC._visible = true;
    }

    _root.play_soundMC.onRelease = function(){
    _root.play_soundMC._visible = false;
    }

    It's kind of a kludge, but it works.

  18. #18
    Member
    Join Date
    Apr 2002
    Posts
    39
    Thanks a lot for your time and help.
    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center