Three ways to add music in Flash

Source: Internet
Author: User

1, the effect: just start to see the Play button, click Play, music began, show Stop button, click the Stop button, music stopped, show the play button, and then click the Play button, music from the beginning of the stop to play.

2, the use of conditions: in the home scene;

3, button layer 1th frame, drag in the Play button and stop button, and give the Play button instance name: PLAY_BTN, stop button instance name: Stop_btn;2 button overlap placement, stop button on the ground floor.

4, in the Flash document to import a MP3 music, open the library, find MP3, right key point it, point link, for ActionScript before the bait, identifier: MP3;

5. Add the following statement on the 1 frame of the as layer in the main scene:

Stop_btn._visible = false;

var mysound:sound = new Sound ();

Mysound.attachsound ("MP3");

var n:number = 0;

Play_btn.onrelease = function ()

{

Mysound.start (n);

This._visible=false;

Stop_btn._visible =true;

};

Stop_btn.onrelease = function ()

{

Mysound.stop ();

n=mysound.position/1000;

This._visible=false;

Play_btn._visible =true;

};

Music data stream Plus lyrics method

New Music Movie clip symbol

1, layer One: Music layer, click on the 1th frame, properties panel: Voice select "Song name", Sync Select "Data Flow", and then expand on the timeline. Click on the 1th frame, add Action script: Stop (); Click on the last 1 frame, insert blank keyframe, plus frame action script: gotoAndPlay (2);

2, Layer Two, the lyrics layer, in the corresponding place on the timeline add the lyrics of each sentence (method slightly).

3, Layer Three, button layer, on the 1th frame put play button, right key button, add Action script:

On (release) {

gotoAndPlay (2);

}

On frame 2nd, put the Stop button, right-click button, add Action script:

On (release) {

gotoAndPlay (1);

}

Automatically extends to the frame at the end of the music playback.

Second, drag the "music" movie clip symbol you just made to the 1th frame of the music layer in the main scene.

Music Pure Data stream method

New Music Movie clip symbol

1, layer One: Music layer, click on the 1th frame, properties panel: Voice select "Song name", Sync Select "Data Flow", and then expand on the timeline. Click on the 1th frame, add Action script: Stop (); Click on the last 1 frame, insert blank keyframe, plus frame action script: gotoAndPlay (2);

Second, in the home scene

1, click the 1th frame of the music layer, drag the music movie clip symbol into, enter the instance name: yy

2, in the button layer on the 1th frame, put the play button and stop button.

Right-click the play button, action, enter the statement:

On (release) {

_root.yy.play ();

Right-click the play button, action, input statement: On (release) {

_root.yy.stop ();

}

Use the reverse method, set the button to control music playback and stop

Script as layer 1th frame in scene:

Stop ();

var j = 0;

var false:boolean = False;

button. Onrelease = function () {

False =! False;

False? Music. Play (): Music. Stop ();

};

This script can be reused for beginners ' friends. Just remember:

1, the button's instance name is: button; 2, the music instance name is: music;

3, can also control other components, as long as the instance name (such as AA), in the curly braces false? Music. Play (): Music. Stop (); add false below? Aa.play (): Aa.stop (); it's OK.

4, the above movie element's instance name may also use the English state to write (if the music is YY, the button is B_an), at this time, the above script "the music" to change for yy, "the button" change for B_an.

5, the decimal point in the script must be entered in the English state.

Add the following script on frame 1th of the home view as layer:

Ks.onrelease = function () {

_root.yp_mc.play ();

};

Zt.onrelease = function () {

_root.yp_mc.stop ();

};

Tz.onrelease = function () {

_root.yp_mc.gotoandstop (1);

};

In the above script, KS is the instance name that plays the music button, ZT is the instance name of the Pause Music button, TZ is the instance name of the Stop Music button, and YP_MC is the instance name of the music movie symbol.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.