Sunday, January 4, 2009

Solve the problem of sound on/of button in flash(Wk11_2)

In my previous flashes assignments I countered a problem is that when replaying the sound again and again. This problem happens when the previous sound is still playing. So, I suggest a solution:

In the replay button we add this code:

on(release)
{

stopAllSounds();
gotoAndPlay(1);

}


In the first frame of timeline add this code :

firstSound=new Sound();
firstSound.attachSound("main");
firstSound.start(0,999);

"main" is the name of linkage of sound imported in the library.

In the "on" button of sound we add this code:

on (release) {

_root.firstSound.setVolume (0);
this.gotoAndStop("off");
}

In the "off" button of sound we add this code:

on (release) {

_root.firstSound.setVolume(100);



this.gotoAndStop("on");

}

This is the most simple way to solve the problem when the sound play again and again at the same time.

Snow or rain in flash(Wk11_1)

During complete my flash assignment on typeface I found that the flash will become more interesting if it contains rain or snow or anything falling down randomly.In order to make this effect, we create a an object with shapes of small circle(for snow) or sharp oval(for rain) in a new layer at the first frame and convert it into a movie clip. In this tutorial I will introduce the way to make a falling snow. After converting to a movie clip, we name it as "snow" in instance of this movie clip. Next, we add this action script code for the movie clip :


onClipEvent (load) {
movieWidth = 350;
movieHeight = 263;

i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;

this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 75+Math.random()*100;
this._x = -10+Math.random()*movieWidth;
this._y = -10+Math.random()*movieHeight;
}
onClipEvent (enterFrame) {
rad += (k/180)*Math.PI;
this._x -= Math.cos(rad);
this._y += i;
if (this._y>=movieHeight) {
this._y = -5;
}
if ((this._x>=movieWidth) || (this._x<=0)) {
this._x = -10+Math.random()*movieWidth;
this._y = -5;
}
}

We must also look at the movieWidth and movieHeight, we must adjust these based on our size of the flash.

after all, we add this code for the first frame in the timeline:

for (k=0; k<50; k++) {
duplicateMovieClip(this.snow, "snow"+k, k);
}

Now, let's check what will happen :) .

Source(Vietnamese): http://www.ngovancong.com/?nvc=act:news|newsid:980