Flash easy to realize the multicolored transformation polygon mouse trajectory effect

Source: Internet
Author: User
Track | mouse | effects

This tutorial is fully implemented using the Flash Action Script command! Using Flash drawing we already know! This tutorial will be for you to review the Flash ActionScript drawing function!

This tutorial makes the mouse follow the effect is very special, is some with the color of the shape of the transformation of some graphics.

First look at the effect. (Use the mouse to move in the animation can see the effect)

Click here to download the source file

Production methods.

First create a new document, and then press Ctrl+j to modify the property.

Then put the following code in the first frame.

/* Define 5 Global Variables * *
var time:number = 0;
var timemin:number = 100;
var alphadrop:number = 2;
var growby:number = 2;
var rotatebymax:number = 10;

/* Transform radians function * *
function Deg2rad (degrees:number): number {
return degrees * MATH.PI/180;
}

/* Returns a number between the maximum and the minimum value * *
function Randrange (Min:number, Max:number): number {
var randomnum:number = Math.floor (Math.random () * (Max-min + 1)) + min;
return randomnum;
}

/*  draws a rule polygon, setting the color, size, radius */
Function Drawpoly (Sides:number, Color:number, Radius:number): MovieClip {
  var depth:number = _root.getnexthighestdepth ();
  var poly_mc:movieclip = _root.createemptymovieclip ("poly" + depth, depth);
  var unitangle = Deg2rad (360/sides);  
 
  Poly_mc.beginfill (color);
  Poly_mc.moveto (radius, 0);
  for (var i:number = 1; i < sides i++) {
    var turn:number = Unitangle * i;
    var dx:number = Math.Cos (Turn) * RADIUS;
    var dy:number = Math.sin (Turn) * RADIUS;
    poly_mc.lineto (dx, dy);
 }
  Poly_mc.endfill ();
 
  return POLY_MC
}

/* Initialize a movie clip * *
function Initpoly (): Void {
this._x = _xmouse;
this._y = _ymouse;
This._xscale = This._yscale = 0;
This.rotateby = Randrange (-rotatebymax, Rotatebymax);

This.onenterframe = function (): Void {
This._xscale = This._yscale + = Growby;
This._alpha-= Alphadrop;
This._rotation + = This.rotateby;

if (This._alpha < 0) {
This.removemovieclip ();
}
};
}

/* Main program * *
OnMouseMove = function (): Void {
if (Gettimer ()-time > Timemin) {
Initpoly.apply (Drawpoly (Randrange (3), Randrange (0, 0xFFFFFF), 100));
Time = Gettimer ();
}
};

Finally Press Ctrl+enter test! See how it works? Isn't it amazing? Learn Flash's ActionScript quickly! Very impressive!



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.