Ping Pong - Sound Menu
| Category | : Flash | Views | : 27776 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : ping-pong-sound-menu.zip | ||
| Result | : See the result | ||||
| <<< Previous | Index Series |
Now go to the actions for the ball and make these changes:
if (_root.Limits.Border.hitTest(this._x + xspeed, this._y + yspeed, true))
{
xspeed = -xspeed;
xspeed *= 1.05;
yspeed *= 1.05;
//create a new sound object
var pong:Sound = new Sound();
//attach the sound from the library using the identifier
pong.attachSound("Pong");
//start playing the sound
pong.start();
}
if (_root.Limits.Pads.hitTest(this._x + xspeed, this._y + yspeed, true))
{
yspeed = -yspeed;
xspeed *= 1.05;
yspeed *= 1.05;
//same as above
var pong = new Sound();
pong.attachSound("Pong");
pong.start();
}
Code Explanation
PlayBtn.onRelease = function()
{
_root.gotoAndStop(2);
}
When the user clicks the "Play" button we go to the frame 2 of the game using the "gotoAndStop(frame)" function.
MenuBtn.onRelease = function()
{
_root.gotoAndStop(1);
_root.Scroll.removeMovieClip();
}
Here, we go to the first frame and remove the "Scroll" Movie Clip.
var pong = new Sound();
pong.attachSound("Pong");
pong.start();
On the first line of this code we create a new Sound object, then we use the function attachSound(identifier) to attach the sound we have on our library. And on the last line we call start() to start playing the sound effect.That's all for this game, test it with Ctrl + Enter. I hope you like this flash game development. See you in the next game!
![]() |
![]() |
![]() |
![]() |
![]() |
| <<< Previous | Index Series |







