Search tutorials
How to Load an External MP3 from a Text Input Box |
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:
|
- Create an input text box and give it a variable name like "songInput" (as
shown below).
- Place a button on stage and put the following code on the button:
on(press) {
if (songInput!=nul && playing!=true) {
playing=true;
myInputSound = new Sound(myInputSoundMc);
myInputSound.loadSound(songInput);
myInputSound.start(myPausePosition,0)
}
}Fig. 19: Example of input-text box properties, showing variable name location
- Place another button on stage for stopping the sound with the following:
on(press) {
//Stop Button
mySound.stop();
myInputSound.stop();
playing=false;
myPausePosition=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.
» Level Intermediate |
Added: 2002-08-13 Rating: 8.98 Votes: 664 |
» Author |
Kenny Bellew is a technical writer in Minneapolis, MN. He's currently interested in becoming involved in other writing-related Flash projects. |
» Download |
Download the files used in this tutorial. |
Download (6170 kb) |
» Forums |
More help? Search our boards for quick answers! |