Current location - Music Encyclopedia - NetEase Cloud Music - How to set up flash to use buttons to control the play and pause of background music
How to set up flash to use buttons to control the play and pause of background music

Open FLASH8, import the sound to be played, set the link attribute of the sound in the library, set the identifier to sound.mp3, and set the link to be exported in the first frame. Return to the scene, create a new video clip, place the music on the video clip timeline, and place the video clip into the first frame of layer 1 in the scene (you may not place it in the first frame of layer 1).

Create a new layer 2, call up your favorite button or the button you made yourself from the public library, and place it on the first frame of layer 2 (blank key frame), name it btn_mc, and add the following at this frame Code: var s = new Sound();//Create a new sound

//Set the link attribute of the sound in the library, set the identifier to sound.mp3, and set the link to export in the first frame

s.attachSound("sound.mp3");//Load the sound identified by this link from the library

var played = 0;//Define the initial sound to start playing from 0 seconds< /p>

pauseed = false;//Mark variable, initially in paused state

//Create a button in the scene and name it btn_mc

btn_mc.onRelease = function( ){

if(pauseed){

stop();//Stop the timeline

s.stop();//Stop the sound

played = s.position;//Number of milliseconds for the current sound to be played

pauseed = false;//Mark variable, this is the paused state

}else{

play();//Playing timeline

s.start(played / 1000, 999);//Start playing from the currently paused sound seconds and play 999 times< /p>

pauseed = true;//Mark variable, it is in playback state

}

}Ctrl+Enter to test it! I have tested it successfully! There will be sound when the flash is opened, the music will pause when the button is pressed, and the music will continue to play when the button is pressed