Core Tip: This article describes two ways to embed an audio file in a flash document so that it can play correctly in Flash Player.
This article describes two ways to embed an audio file in a flash document so that it can play correctly in Flash Player.
1, the establishment Sound object uses the load () method to load the external MP3 to play;
2. Let the Sound object monitor the Sampledata event so that the sound generated dynamically by the program can be played, for example:
The following example plays a simple sine wave.
The following is a reference fragment:
var mysound:sound = new Sound ();
function Sinewavegenerator (event:sampledataevent): void {
for (var c:int=0; c<8192; C + +) {
Event.data.writeFloat (Math.sin (c+event.position)/MATH.PI/2) *0.25);
Event.data.writeFloat (Math.sin (c+event.position)/MATH.PI/2) *0.25);
}
}
Mysound.addeventlistener (Event.sample_data,sinewavegenerator);
Mysound.play ();