The production of the vibration button in Flash

Source: Internet
Author: User
Tags setinterval
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.


Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.