Tutorials | bounce
First look at the effect of adding random colors:
One: Build a MC named: Beat the Pillar, and then draw a small rectangle here.
Second: To build a MC named: The next part of the jump pillar, the beating of the pillars dragged into the scene: and then 5,10,15,20,30. Frame Insert KeyFrames (F6) to animate these frames.
Third: To build a film called: the top block of the movie, draw a small rectangle.
Four: To build a single jumping column of the film elements, will be the next part of the Jump column and the top block into the top block placed above. The lower part of the pillar is below.
Five: To build a MC named: Seven Jumping pillars, drag eight single jumping pillars, respectively, the instance name: Bar1-bar8.
Then write the code in the first frame:
This._parent.mysound.setvolume (100);
Set the volume of music
var Num = 8;
The number of bouncing columns
var space = 2;
Space between the top block and bar
var Soundon = true;
Identifies the music switch's identifier and is set to
var i = 1;
while (I<=num) {
MyColor = new Color (this["Bar" +I].BARMC);
Mycolor.setrgb (Random (0XFFFFFF));
this["Bar" +i].barmc.gotoandplay (Random (this["bar" +i].barmc._totalframes));
Sets the music bounce column to start playing in the random frame of the total frame number of the BARMC
/////////////////////////////////////////////
this["Bar" +i].onenterframe = function () {
Always detect the position of the top bar. Let it follow the BARMC.
var bar = this;
Trace (Bar.barmc._yscale)
if (Soundon = = True) {
If the music is playing state
if (-bar.barmc._height-space<bar.topmc._y) {
Set the position of the top jump block
bar.topmc._y = -1*bar.barmc._height-space;
Set the position of the top block to the height of the runout block (this height is randomly changed)
}
bar.topmc._y = bar.topmc._y+7.000000e-001;
Return
}
};
//////////////////////////////////////////////////
++i;
}
Stop ();
VI: Add the Music play code to the scene:
var mysound:sound=new Sound ()
Mysound.attachsound ("S1")
Mysound.start (5,1) dragged seven bouncing pillars into the scene.
Flash source file Download:music.rar