How to Use Flash MX Sound Objects

This document copyright © 2004 by Kenny Bellew of Cowfly.Com Design, kennybellew@hotmail.com
How to Load an External MP3 from a Text Input Box Return to Index Do you want all FLA's used for this tutorial? Do you have a question?

If you want to be able to type in the file name of an MP3 file into a text box, and press a button to have that file play, the following could be used:

Fig. 18: Example of loading an external MP3 file from a text input box
  1. Create an input text box and give it a variable name like "songInput" (as shown below).
     
  2. Place a button on stage that will be used to load the sound, and put the following code on the button:

on(press) {
// loadSound button
_root.myInputSound = new Sound();
_root.myInputSound.loadSound(songInput);
//
_root.myInputSound.onSoundComplete=function() {
_root.playing=false;
_root.paused=false;
_root.stopped=true;
_root.myInputSoundPosition=0;
_root.myInputSoundPositionText=0;
}
}

 
    Fig. 19: Example of input-text box properties, showing variable name location
  1. Place another button on stage for stopping the sound with the following:


on (press) {
//Stop Button
if (_root.playing==true) {
_root.playing=false;
_root.paused=false;
_root.stopped=true;
_root.myInputSound.stop();
_root.myInputSoundPosition=0;
_root.myInputSoundPositionText=0;
}
}

This is one case in which you have to break the rule of defining all sound objects in the same location. When the button is pressed, the value of "songInput" is inserted during the sound object definition.

  1. Place a play button on stage, and insert the following code into its action panel.
on (press) {
if (_root.playing!=true) {
_root.playing=true;
_root.paused=false;
_root.stopped=false;
if (_root.stopped==true) {
_root.myInputSound.start(0,0);
} else
_root.myInputSound.start(_root.myMusicPosition,0);
}
}

 

 

 

Previous Next
How to Load an External MP3 Dynamically as a Sound Object using the loadSound Method How to Build a Preloader for Dynamically Loaded MP3's
Return to Index Do you want all FLA's used for this tutorial? Do you have a question?

This document copyright © 2004 by Kenny Bellew of Cowfly.Com Design, kennybellew@hotmail.com