A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: loading sounds with urlrequest, i dont understand.

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    418

    loading sounds with urlrequest, i dont understand.

    in this piece of code:
    PHP Code:
    var mySoundReq:URLRequest= new URLRequest("samplesound.mp3");
    var mySound:Sound = new Sound();
    mySound.load(mySoundReq);

    How does the urlrequest know where that .mp3 file is located, and how do i tell as3 where it is?

    and another thing: when i put this on the web, how do i locate the file then?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    In that scenario, "samplesound.mp3" is a relative URL, indicating that the file samplesound.mp3 is in the same directory as the swf file.

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    what if its not in the same file, or if it's a nested file? i cant seem to get it to work.

    and what if it's on the internet?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Not in the same file, in the same directory. It corresponds to a directory structure like this:

    parentfolder

    movie.swf
    samplesound.mp3

    If your samplesound is in a subdirectory, say "sounds", like this:
    parentfolder

    movie.swf
    sounds

    samplesound.mp3

    then your urlrequest would change to this:
    Code:
    var mySoundReq:URLRequest= new URLRequest("sounds/samplesound.mp3");
    On the internet, it's exactly the same, as long as the structure appears the same to the browser.

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    ah i get it ok. but what if the movie.swf is in a subfolder of the folder that contains the filder that contains the sound-files?

    and what if you want to use a class for multiple .fla files, that are at different folders?

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Quote Originally Posted by omniscient232
    ah i get it ok. but what if the movie.swf is in a subfolder of the folder that contains the filder that contains the sound-files?
    Like this?:
    parentfolder

    samplesound.mp3
    swfs

    myMovie.swf

    Then you use ".." to traverse the hierarchy upward
    Code:
    var mySoundReq:URLRequest= new URLRequest("../samplesound.mp3");
    and what if you want to use a class for multiple .fla files, that are at different folders?
    Then you do not hardcode the url. Pass it in as an argument. Or you could use an absolute url, but that will change between local and internet deployment

    Code:
    var mySoundReq:URLRequest= new URLRequest("http://mysite.com/sounds/samplesound.mp3");

  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    that makes sense. thanks alot!

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