Button | Vibration How to make vibration button? The main solution is to use the x-axis, y-axis coordinate changes to complete the vibration effect.
Specific steps
One of the easiest ways to do this is to place a button on the button's 4th frame "click" On a movie clip that vibrates on the frame. This is OK. But today we are going to introduce you to the effect of using the As method to implement a motion button.
1. We want to prepare 5 movie clips, place 5 button graphics respectively. As shown in Figure 1.
2. Drag and drop the 5 movie clips from the library into the scene, sorted in order. Named M0,m1,m2,m3,m4, respectively, in the following property panel. As shown in Figure 2.
3. Create a new layer and add as as in frame 1th:
for (var i = 0; i<5; i++) {
var tmpname = ["M" +i];
_root[tmpname].onrollover = function () {
MyName = This._name;
Btnx = _root[myname]._x;
Btny = _root[myname]._y;
Shakeitnow = SetInterval (Shakeit, 10);
};
_root[tmpname].onrollout = function () {
Clearinterval (Shakeitnow);
_root[myname]._x = btnx;
_root[myname]._y = Btny;
};
}
function Shakeit () {
_root[myname]._x = btnx+ (Math.Round (Math.random ()) *5);
_root[myname]._y = btny+ (Math.Round (Math.random ()) *5);
Updateafterevent ();
}
4. Inside have main as:
for (var i = 0; i<5; i++) {//Because there are 5 buttons, you have to loop 5 times
var tmpname = ["M" +i];//for button renaming
_root[tmpname].onrollover = function () {//mouse over the pointed button
MyName = This._name;
Btnx = _root[myname]._x;
Btny = _root[myname]._y;
Above is to define the initial position
Shakeitnow = SetInterval (Shakeit, 10);//Call function (SetInterval to use look at the following comments bar:)
};
_root[tmpname].onrollout = function () {//mouse slide out of the pointed button
Clearinterval (Shakeitnow);//See Name to know Yes, clear a use setinterval statement
_root[myname]._x = btnx;//Position Restore
_root[myname]._y = Btny;
};
}
Vibration settings
function Shakeit () {
_root[myname]._x = btnx+ (Math.Round (Math.random ()) *5);
_root[myname]._y = btny+ (Math.Round (Math.random ()) *5);
Updateafterevent ()//Refresh function
}
5, okay, let's test the effect.