Imajine Blog Imajine Articles
Contact Me

Preloading MP3 files

To preload MP3 file, we can use 'setinterval()'  function to create polling mechanism that checks the bytes loaded for a Sound or NetStream object at predetermined intervals. We can use 'Sound.getBytesLoaded()' and 'Sound.getBytesTotal()'  methods to track downloading progress of MP3 files.

The following example uses 'setInterval()' to check the bytes loaded for a Sound object at predetermined intervals.

preload an MP3 file:

  1. Create a new FLA file called preloadMP3.fla.
  2. Create a text filed on the canvas, change it to 'Dynamic Text' field in the properties window
  3. Give an instance name 'perload_txt' to this Dynamic text field
  4. Select Frame 1 on the Timeline and type the following code in the Actions panel:

    var songTrack:Sound = new Sound(); 

    function checkProgress (soundObj:Object):Void
    {
    var numBytesLoaded:Number = soundObj.getBytesLoaded();
    var numBytesTotal:Number = soundObj.getBytesTotal();
    var numPercentLoaded:Number = Math.floor(numBytesLoaded / numBytesTotal * 100);

    if (!isNaN(numPercentLoaded))
    {
    perload_txt.text = numPercentLoaded + "% loaded.";
    trace(numPercentLoaded + "% loaded.");
    }

    };

    songTrack.onLoad = function ():Void
    {
    perload_txt.text = "load complete";
    trace("load complete");
    clearInterval(poll);
    }; 

    songTrack.loadSound("http://www.imajine.in/flash/Welcome.mp3", true);
    var poll:Number = setInterval(checkProgress, 100, songTrack);

  5. Select Control > Test Movie to test the sound.

    The Output panel shows loading progress.

    Click here to download the source file

Tags: Load external MP3 file into flash, Preload MP3 File, play mp3 file, Sound Object in Flash, Preload and play music, flash music preloader

Download Free Photo Gallery

Download Free Photo Gallery

You can download Imajine's Scrapbook Photo Gallery absolutely free of cost and to customize , you need no knowledge of Adobe Flash.  Click here to view Scrapbook Photo Gallery / download

Tutorials
Flash Tutorials
Horizontal 3D Carousel
MP3 Player
Scrapbook Photo Gallery
Text Enhancement
Color object
Glow effect using actionscript
Drawing with actionscript
Blur Effect
Load external .mp3 file
Preload external .mp3 file
Sound Controller
Set volume of externally .mp3 file
View MP3 song details
Actionscript blur effect
Actionscript fade in / out effect
Fireworks Tutorials
Custom Stroke
Typography / Ink blot effect
Photograph focus effect
Rainbow Pattern
Inset Text Effect
Fuzzy Light Blending Mode
Little bulb effect
Old paper effect
'Post it' effect
Hand drawn designs
Black/White and Sepia tone
Water color painting effect
Vintage effect on vector graphics
Solid color, black/white
Photoshop Tutorials
Photo editing
Purple Haze

Portfolio

Logos
Website design
CMS Customization
Flash
Web development
Print


Download free textures and patterns and use it for your personal use.

Click here to download Textures and Patterns.

Download free birthday cards

Free Birthday Cards
Click here to view Imajine's free downloadable birthday cards for personal and corporate use. Imajine's birthday cards are in jpeg format so it is faster to download and send in your wishes to your friends and family.
Bookmark and Share Tell a Friend jayanthi.varma@imajine.in  |  © 2008 Imajine