dcsimg
A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: loadSound toggle button

  1. #1
    Junior Member
    Join Date
    Aug 2002
    Posts
    7
    LOADSOUND
    mySound = new Sound();
    mySound.loadSound("mp3/intro/8.mp3",true);
    mySound.onSoundComplete = function() {
    nextScene();
    }

    I'm working on an introduction piece that has sound loaded with the code above (attached to first frame of a scene). I would like to script a button that would toggle this sound on/off using scripting only (one frame). I'm thinking some sort of if...else statement with mySound.start() and mySound.stop(). i'm a graphic designer and not much of an actionscript coder, and i need a little help getting started here. any help is appreciated. please contact me if you need additional info. here's my best guess


    MY BEST GUESS
    on (release) {
    if (mySound.duration > 0) {
    mySound.stop();
    } else {
    mySound.start();
    }
    }

  2. #2
    Senior Member
    Join Date
    Mar 2001
    Posts
    384
    on (release) {
    if (mySound.position > 0) {
    mySound.stop();
    } else {
    mySound.start();
    }
    }


  3. #3
    Junior Member
    Join Date
    Aug 2002
    Posts
    7
    i tried that solution shortly after my initial post. when the page loads, the sound automatically plays. if i press the button, the sound stops. however, when i repress the button to restart the sound, it does nothing.

    i also noticed if i refreshed the html page, it does not load the mp3. if i press the button, it plays the sound and if i press it again, it stops. however, if i try to button again, nothing happens.


  4. #4
    Senior Member
    Join Date
    Mar 2001
    Posts
    384
    ok, I'd suggest setting a variable to test for instead of using the time thing- if you've stopped the sound once it starts playing, I think that the position will return its last played position.

    so,

    make sure the sound plays every time:
    mySound.onLoad=function(){
    mySound.start();
    playing=true;
    }

    then, with your button say:

    on(release){
    if(playing==true){
    mySound.stop();
    playing=false;
    }else{
    mySound.start();
    playing=true
    }

  5. #5
    Junior Member
    Join Date
    Aug 2002
    Posts
    7

    Smile

    Thank you very much for your advice, you saved me a lot of time and frustration.

    just one thing to note. while the button works really well, the sound still does not play when i refresh the browser. i have to clear the temporary internet files in the browser, and then refresh in order for the sound to start playing automatically. anyway, here is the final code i used for those interested.

    CODE ON FRAME 1
    function advance() {
    nextScene();
    }
    stop();
    mySound = new Sound();
    mySound.loadSound("mp3/intro/1.mp3",true);
    mySound.onSoundComplete = advance;
    mySound.onLoad=function(){
    mySound.start();
    playing=true;
    }

    CODE ON BUTTON
    on(release){
    if(playing==true){
    mySound.stop();
    playing=false;
    }else{
    mySound.start();
    playing=true
    }
    }

    Thanks again, Peter
    [Edited by murb75 on 08-12-2002 at 04:37 PM]

  6. #6
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    Are you sure that works with the sound loading as streaming (true)? Have you tried it in both Netscape and IE? There's a know bug using start() with a sound object loading as streaming. I've been able to get it to work in Netscape with the r40 release, but not in IE.

  7. #7
    Junior Member
    Join Date
    Aug 2002
    Posts
    7
    i just tested it out on Netscape 6.2 and the button functionality only seems to work once (stop only). however, if i refresh the html page, it DOES automatically play the sound, something i could not get it to do in IE.

    i only need the button to function in IE 5.5+, so i am happy with the code as it seems to work fine. however, if anyone has anymore feedback or suggestions on how to make this code more dynamic, i would like to hear them.

    by the way, i have only tested this out on IE 5.5 and NN 6.2 for the pc platform. i'll check it out tonight on my mac.

  8. #8
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    Interesting. I'm using IE 6.0 on the PC. I know for sure I cannot use the mySoundObject.start() after stopping a streaming dynamically loaded MP3 in IE 6.0. I'd really like to be able to test this across a variety of brower versions and platforms.

  9. #9
    Junior Member
    Join Date
    Aug 2002
    Posts
    7
    Unfortunately, I did not get the opportunity to test this script on my mac last night. However, I did test it out on IE 6.0 on the PC this morning, and it seems to work fine.

    I read the flashMX instructions manual and another flashMX book, and they too said that .start() would not work for an external streaming mp3. They said to use loadSound(). I'm not sure why this appears to be working. If you have any more insight I would appreciate it.

    Kenny, I can not release the URL on this site, but if you would like to view this movie in action, I can e-mail you a link. If not, please drop this script in a movie and test it out yourself.

  10. #10
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    I know that they say that it is supposed to work. It was a bug that was supposed to be addressed in the r40 player.
    See: http://www.macromedia.com/support/fl...player_r40.htm

    Not only have I experienced this problem with IE, but I know of at least two others who have told me that they have experienced the same thing. So, I'm just really curious.

    Yes, I would be interested in testing your file. Also, I've thrown together a simple file that loads an external MP3 as streaming and have included a start and stop button.

    Please take a minute to see if you can restart the sound with the play button after stopping it with the stop button. Click on the link below to test this. I'm going to see if I can get a variety of browsers to test it. Thanks.

    http://aspirin99.guardianhosting.net/tutorial/test.htm

    Kennyb

  11. #11
    Junior Member
    Join Date
    Aug 2002
    Posts
    7
    I tested your file and it worked just fine. NOTE: my file's pretty much the same as the tester file you sent me with the exception that the sound loads on the first frame of the scene instead of an on(press) action.

    BROWSER/PLAYER USED IN TESTING
    Microsoft Internet Explorer 5.50.4807.2300
    Flash Player 6.0.47.0

    Thanks Kenny for your interest, and let me know what you find out. I, too, am really curious.

    P.S. Unfortunately, I will not be able to e-mail you a link to my file as there are some property/project disclosure issues here at work. However, once my personal DSL service is set up in my apartment, I will send you a link to my personal site.

  12. #12
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    Thanks, I'm going to post this to a broader audience to see if I can get more data.

  13. #13
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    Okay, I think I figured it out. I tried re-installing the latest player (I just installed it a few days ago). The problem continued.

    On a hunch, I deleted my cache, restarted and reinstalled the latest player again. Incredibily, it worked. It's doesn't make sense, but it worked.

    A caution though- I tried this on a Mac and a PC running older versions. I was able to get both to work by updating the Flash Player. I worry that if you're using start() for a streaming sound that it will not work for a good majority of folks who are still running the old 6 players. You might want to consider reloading the sound instead of using start().

  14. #14
    Junior Member
    Join Date
    Aug 2002
    Posts
    7
    Okay...that makes sense now.

    As I've said before, I'm a graphic designer by trade and a flash hack on the side. What would be the best solution for this as far as actual code/syntax? The reason I ask is that your code in your example differed from mine. Is there a better way to code this than my original attempt?

    Thanks again.

  15. #15
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    Well, in looking at your code, one thing it looks like you may not know - If you load the sound as streaming, the sound starts without using the start() call. This is not true when loaded as an event. So, you could just leave the...

    mySound.loadSound("mp3/intro/1.mp3",true);

    ...and remove the...

    mySound.start();

    Then, when you need to restart the sound, just reload it with loadSound.

    The other options is to require the absolute latest plugin when the user views your page. Check out the Flash Deployment Kit for examples of how to do that.

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