Ultrashock Forums > Archived Forums > Sound
preloading sound.

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
preloading sound.
Old 2006-11-22

Hey guys,

I have this issue:

My whole content, the flash site is 80kB.

If i load one mp3 as an ambient music, it jumps to 400kB, which is not so good.

I was wondering is there any possible way that I could load the content as 80kB, and once its completely loaded, to begin loading the ambient sound ? also perhaps this sound should stay in a different swf or something so that it does not extend my main swf too much?

Thanks in advance for suggestions.
postbit arrow 8 comments | 515 views postbit arrow Reply: with Quote   
Registered User
stormBliss is offline
seperator
Posts: 568
2004-07-22
Age: 28
seperator

Ultrashock Member Comments:
nonak's Avatar nonak nonak is offline nonak lives in Canada 2006-11-22 #2 Old  
Last edited by nonak : 2006-11-22 at 17:13.
Hi Stormbliss

you could try streaming the sound in..

if you need it loaded as an event sound , you can load it into a movie clip once the rest of the movie is playing...

just a couple thoughts..
Reply With Quote  
stormBliss stormBliss is offline 2006-11-23 #3 Old  
Hey mate, thanks for your answer.

I need this sound to be my background music for the website, so its not an object event (well it is an event actually if you think of it as playing when the _root.onLoad=function() - so when the root loads).

I am a bit confused, can you please point me in the right direction about the streaming suggestion? a bit of code would be much appreciated.

So actually, all I need is that I load this sound file from outside my main swf , even if that means inserting it into another separate swf . by doing so, it will not modify the size of my main swf.
Reply With Quote  
BVX BVX is offline BVX lives in Denmark 2006-11-23 #4 Old  
this topic is beaten to death, u could search a bit in the forums, anyway hope that helps:

http://www.kennybellew.com/tutorial/drag.htm
Reply With Quote  
BVX BVX is offline BVX lives in Denmark 2006-11-23 #5 Old  
as simple as possible:

ActionScript Code:
  1. var audio:Sound = new Sound();
  2. audio.loadSound("URL", true);
  3. audio.start();

true/false toggles stream/download mode
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Nutrox lives in United Kingdom 13 Creative Assets 2006-11-23 #6 Old  
The Sound class also has getBytesLoaded() and getBytesTotal() methods, so you can check the load progress easily enough if you don't want to stream the audio.

ActionScript Code:
  1. var mySound:Sound = new Sound();
  2. var loadInterval:Number;
  3.  
  4. function loadSound(url:String):Void
  5. {
  6.    if (loadInterval)
  7.    {
  8.       clearInterval(loadInterval);
  9.    }
  10.    mySound.loadSound(url);
  11.    loadInterval = setInterval(this, "checkLoadProgress", 100);
  12. }
  13.  
  14. function checkLoadProgress():Void
  15. {
  16.    var percent:Number = 0;
  17.    var bLoaded:Number = mySound.getBytesLoaded();
  18.    var bTotal:Number = mySound.getBytesTotal();
  19.  
  20.    if (bLoaded && bTotal)
  21.    {
  22.       percent = (100 / bTotal) * bLoaded >> 0;
  23.    }
  24.  
  25.    if (percent == 100)
  26.    {
  27.       clearInterval(loadInterval);
  28.       loadInterval = null;
  29.  
  30.       mySound.play();
  31.    }
  32. }
  33.  
  34. //
  35.  
  36. loadSound("ambience.mp3");
Reply With Quote  
BVX BVX is offline BVX lives in Denmark 2006-11-23 #7 Old  
thanks, Nutrox - flawless like always!
Reply With Quote  
stormBliss stormBliss is offline 2006-11-23 #8 Old  
thank you BVX, and Splat - you are amazing, that was my next question
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Nutrox lives in United Kingdom 13 Creative Assets 2006-11-23 #9 Old  
No problem.

There is also the Sound.onLoad event that you can use when the sound has loaded... if you don't need any load progress info.

ActionScript Code:
  1. mySound.onLoad = function():Void
  2. {
  3.    trace("mySound has loaded");
  4. }
  5.  
  6. mySound.load("file.mp3");
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: