A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 49

Thread: Embedding sound files

  1. #1
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282

    Embedding sound files

    Hi

    I'm using

    ding = new Sound();
    ding.loadSound("ding.mp3");
    ......
    _root.ding.start();

    to play a sound using action script.

    The problem is I can't workout how to have the sound file embedded in the movie as is the case when using the add sound wizards for button actions.
    At the moment the mp3 is in the same folder but separate on the server which works but seems a bit clumsy.

    I have looked around but not found any info on this but could be missing the obvious here

    regards

    mike

  2. #2
    Junior Member
    Join Date
    Sep 2005
    Posts
    21
    Is there a way to reference a sound file outside of the flash file. A friend of mine explained to me that this is a way to keep the flash file small and minimize the loading time. He said that if I embed the sound file in the flash file, that will make the flash file 3-4 times larger and thus taking longer to load.

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    is there a way to reference a sound file outside of the flash file.
    That's exactly what he's doing in the code above. and your friend is right. That's why I don't understand why indogo wants to embed it.

    At the moment the mp3 is in the same folder but separate on the server which works but seems a bit clumsy.
    actually rather than clumsy it's the preffered way to go.

  4. #4
    Senior Member
    Join Date
    Jun 2000
    Posts
    3,512
    To embed, use the link button in the action script editor to assign a link name to the sound and use the link name in attachSound.

  5. #5
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Ok thanks bob.........there's always an answer....just have to ask the right question....cheers..

    Blanius the sound files are both 2k and the flash is 25k so the extra overhead is minimal and i have an obsession with tidiness which the clinic is helping me with.

    Thanks for the feedback all

    regards

    mike

  6. #6
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    So simple when yer know how..

    Worked a treat......I have a learning curve resembling the Alps

    many thanks

    mike

  7. #7
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    For thread completeness the second line becomes

    ding.attachSound("linkname");

  8. #8
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    Is this the same code I'd use to stream music for an entire movie?

    Maybe I should be creating an on/off music button?
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  9. #9
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    mySound = new Sound();
    mySound.loadSound("samples/butterflies40.mp3", true);
    mySound.start();

    is what you would need to stream music..........'true' to stream 'false' to load the whole file before playing.With suitable comprssion music can be played continuously on dial up.
    The link can be absolute or relative.
    if you wish to sync the movie with the sound then the technique is more involved.there is a thread on here to do with lipsyncing and probably others as the movie will play at a different speed on different machines but the music will normally play at its normal speed.
    It can be used in a button using on(release){'the above'}
    and stopped using stopSound..
    Hope this helps

    mike

  10. #10
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    Thanks. I'll give this a go and let you know if I succeeded.
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  11. #11
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    Ok, here is what I did.

    I made a small file and put a button in it.
    Then I put this in the button.
    Code:
            on(release){
            mySound = new Sound();
            mySound.loadSound("come.mp3", true);
            mySound.start();
    }
    But nothing happens. Any thoughts?
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  12. #12
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Quote Originally Posted by dniezby
    Ok, here is what I did.

    I made a small file and put a button in it.
    Then I put this in the button.
    Code:
            on(release){
            mySound = new Sound();
            mySound.loadSound("come.mp3", true);
            mySound.start();
    }
    But nothing happens. Any thoughts?
    Your code works for me. The export setting should be at least flash 6. I made a shape, made it into a button, added your code into the actionScript and it played.
    Any programming language is at its best before it is implemented and used.

  13. #13
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    I had to close KM and reopen the file for it to work....strange.
    Anyway it works now but how do I get it to keep playing throughout the movie?
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  14. #14
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    what is it doing? I should play to the end of the song. I forgot to tell you about closing the file and reopening it.
    Any programming language is at its best before it is implemented and used.

  15. #15
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    What is it with you? Do you have some type of powers? Everytime I say something doesn't work after I've followed your steps, then go back to try again it suddenly works.

    Maybe you can tell me what's wrong with my car? LOL.

    Well, everything seems to be working now...(Knock on wood)
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  16. #16
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Quote Originally Posted by dniezby
    What is it with you? Do you have some type of powers? Everytime I say something doesn't work after I've followed your steps, then go back to try again it suddenly works.

    Maybe you can tell me what's wrong with my car? LOL.

    Well, everything seems to be working now...(Knock on wood)
    I have played around a lot with the mp3 a lot, while spending little time learning useful stuff like php. I also practice witchcraft.
    Any programming language is at its best before it is implemented and used.

  17. #17
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Yep flash 6 is a must.

    Is the swf file and the mp3 file in the same directory?
    Also if you embed the file into a webpage the address will be relative to the webpage and not where the swf comes from.

    I just lay my hands on things to get them to work but only for others.never works for myself..

    Do you have a stopSound somewhere in the movie as otherwise the sound should play to the end.
    Have fun

    mike

  18. #18
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    Yeah, everything is working now.

    What I finally did was put this in the first frame.
    Code:
    // Load and play music at start
    mySound = new Sound();
    mySound.loadSound("come.mp3", true);
    mySound.start();
    btn_soundon._visible = true;
    And this in the sound button action:
    Code:
    //Turn sound off, show sound on button
    on(release){
       btn_sound_off._visible = true;
       btn_sound_on._visible = false;
       mySound.stop();
    }
    This action went into the button action that turns the sound back on.
    Code:
    // Turn sound on, show sound off button.
    on(release) {
        btn_sound_off._visible = false;
        btn_sound_on.visible = true;
        mySound.start();
    }
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  19. #19
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    To streamline the code if the off button is laid over the top of the on button then only the off button needs to be toggled visible/invisible if you see what I mean.

    A question........if for a server that does not allow mp3 I embedded the sound file into a flash movie which is then loaded by the main/control movie what would be the best way to still stream the sound......by setting streaming in the sound flash movie or can the flash be streamed by the main movie ?.if again you see what I mean

    regards and merry christmas

    mike

  20. #20
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Quote Originally Posted by indogo
    To streamline the code if the off button is laid over the top of the on button then only the off button needs to be toggled visible/invisible if you see what I mean.

    A question........if for a server that does not allow mp3 I embedded the sound file into a flash movie which is then loaded by the main/control movie what would be the best way to still stream the sound......by setting streaming in the sound flash movie or can the flash be streamed by the main movie ?.if again you see what I mean

    regards and merry christmas

    mike
    If I understand what your saying, The server that you use does not allow mp3's to be uploaded. If you embed the mp3 by not clicking the stream checkbox, then the server only sees a swf. Using stream is something that you can try and see if it works. Anytime you stream a mp3, it is loaded seperatly from the swf. If you embed the mp3, then you upload only the swf because the mp3 is inside of the swf. If the mp3 files are mega size then stream, If the are say 20kb, I say embed. This is only my opinion here.
    Any programming language is at its best before it is implemented and used.

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