A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Flash MP3 player

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Posts
    8

    Flash MP3 player

    Hello.

    I am working on a Flash header that plays 1 song and only has a "play" and "stop" button. The music plays fine and starts and stops when the buttons are pushed, but is there a way/cookie for Flash to remember if the user pushed "stop" on the home page and goes to another page so the Flash does not reload the song from the beginning again? The song remains "stopped" until the "Play" button is clicked again to hear the song?

    Basically, Flash would "remember" what the user clicked on on the home page and carry that through the other pages.

    The song loads externally. Here is the example: http://www.broadwayseriessouth.com/index.php

    This is the code I am using to load the external MP3 on the homepage (it has a pause function because the client isn't sure if they want to keep a pause function or not):

    // play button function
    function playit() {
    ply = true;
    stpd = false;
    if (pus) {
    _root.dd.start(position);
    _root.information.info = "Playing";
    pus = false;
    } else {
    _root.dd.stop();
    stopAllSounds();
    _root.dd.start();
    _root.information.info = "";
    _root.information.play();
    _root.information.info = "Playing";
    }
    }
    //pause button function
    function pauseit() {
    if (!_root.stpd) {
    position = _root.dd.position/1000;
    if (!pus) {
    _root.dd.stop();
    pus = true;
    _root.information.info = "";
    _root.information.play();
    _root.information.info = "Paused";
    } else {
    _root.dd.start(position);
    pus = false;
    _root.information.info = "Playing";
    }
    }
    }
    //stop button function
    function stopit() {
    if (!stpd) {
    _root.dd.stop();
    stpd = true;
    _root.information.info = "";
    _root.information.info = "Stopped";
    _root.information.play();
    }
    }

    Thanks for your help!

  2. #2

  3. #3
    Junior Member
    Join Date
    Aug 2008
    Posts
    8
    Thanks! I have not used a Shared Object before. Can you tell me how or what I need to do for these 2 items from your tutorial?

    2.) also inside this header your going to have to:
    a.) check for this Shared Object on the users machine
    b.) check the data inside of it to see if the header should play again...or just be 'still'.

    Thanks again!

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    huh??

    in you header..you'll have the SO (shared Object) code...

    what this does is CHECK for the 'cookie (SO) .....if NOT there...it makes one..and sets the variable to true (or whatever) (ie: played = true)

    everytime you load the header in any page it is embedded in, it will check this cookie.. if its true...it wont play..if false or not there at all.. it WILL play.

    here is an example: very simple:

    PHP Code:
    //load your sharedObject called 'displayCookie'
    var mySharedObject:SharedObject SharedObject.getLocal("displayCookie");
    if (
    mySharedObject.data.displayed == true) {
        
    //do whatever IF already been played
        
    trace("cookie found");
    } else {
        
    trace("cookie not found, setting it now");
        
    //do whatever if NOT already been played
        
    mySharedObject.data.displayed true;
        
    mySharedObject.flush();
    }

    button1.onPress = function(){
        
    mySharedObject.data.displayed false;
        
    mySharedObject.flush();

    make a new .fla, all it needs is this code, and a button named 'button1'.

    the button1 code is just there so you can see how to set the cookie to false again..and hence 'play' your header again.

    you would ONLY need the code that I put on button1 IF/WHEN you ever want to reset things so a user WILL see the header again.

    thats all you need.

  5. #5
    Junior Member
    Join Date
    Aug 2008
    Posts
    8
    Thanks! I will give this a try.

  6. #6
    Junior Member
    Join Date
    Aug 2008
    Posts
    8
    Hi Whispers.

    I added the code, but wasn't sure if I had it all correct since this is my first SO. I have attached the .fla If you get a chance would you mind looking at it to see if I have it correct?

    http://www.dougbrowndesign.com/clien...th/header2.fla

    Thanks again!

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    holy crap..why is it soo big? do you have the MP3 embedded into the .fla?

    you should be loading it externally... (well I suppose that IS up to you)

  8. #8
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    (sigh)

    if you are NOT using AS3 code.. PLEASE (please) always save you files to F8 compatible..otherwise it just waste the time of those trying to help if they dont have (or use) CS3...

  9. #9
    Junior Member
    Join Date
    Aug 2008
    Posts
    8
    Do you need me to resave the file to Flash 8? Why does it waste time?

  10. #10
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Yes. I need you to save it as Flash 8 compatible file (as mentioned above)

    why does it waste time?

    1.) you didnt mark the version of Flash you are using when you posted your thread (as directed too)

    2.) I sat here here trying to help, and downloaded a file (on a crappy internet connection) that wasnt .zipped, with good intentions of helping..only to find out I cant even open the file.

  11. #11
    Junior Member
    Join Date
    Aug 2008
    Posts
    8
    Sorry I didn't mean to waste your time. This is my first time using the forum for help. I've saved the file back to 8 and zipped it.

    Thanks for your help and it should download very quickly for you this time.

    http://www.dougbrowndesign.com/clien...header2-F8.zip

  12. #12
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    no worries.. dont take it as I was yelling...

    more of a canned statement... since I have to say (alot) around here..

    this is a great place.. and being new to a forumm can be daunting just to find your way around..much less know all the rules right away.. just take some time and peek around at the STICKIES at the top of each forum/section to know what is the general 'rule/attitude' for that specific section.

    hopefully I'll get some time to peek at it tonight..if not in the AM.

  13. #13
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    ok.. I looked at the .fla

    Im not sure you need the code for the buttons.. that was just to show you how you can set it back FALSE (hence, making the MP3 play again when it loads)

    what you need to do here:

    //do whatever IF already been played
    trace("cookie found");

    is add some code that does NOT start your MP3 playing.. or STOPS it..whatever you choose.. Im not sure HOW you are setting it all up really..

    you could just pout your code in that if() statement.. so when the ELSE{} code runs it starts your MP3.. if not you do nithing..

    does that make sense?

    so where you have your soundObject code.. wrap that in the else portion...

    also do NOT forget to give your buttons instance names...

    your stop start/play button shoudl have the code that I have for the button..

    and the stop button should be reverse..making it TRUE (as in.. Ive heard it already,, DO NOT play it again on a new page)

    do NOT put the code directly on yoru button..but in the same frame as your other code.. and give your buttons instance names..

  14. #14
    Junior Member
    Join Date
    Aug 2008
    Posts
    8
    Sorry I didn't get to your response sooner. I didn't get an email alert that you posted a response.

    Anyway, thanks for the guidance. I have made the updates, but I think I may be making it worse with my lack of AC experience. I hate to ask you to look at the file again to see how bad I messed it up, but if you have a moment would you mind taking a peek at it? If you don't have time to look at it no worries I've bugged you enough as it is.

    All that I would like to do is when the homepage loads, the song plays and if the user clicks "stop" the music stops. Then when they go to another page the music remains stopped. I am probably over simplifying this and it is a lot more involved than I thought to do it in AC.

    Thanks so much for all of you help and sorry I am such a pain

    http://www.dougbrowndesign.com/clien...header2-F8.zip

  15. #15

  16. #16
    Junior Member
    Join Date
    Aug 2008
    Posts
    8
    Sorry about that, I uploaded the wrong file. The right file should be there now.

    Thanks!

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