Flash in the flower effect AS3 implementation code

Source: Internet
Author: User
Tags addchild

The following is the flash petal effect of the AS3 code, if you want to enjoy the Flash animation effect see the animation at the bottom of this article.

The code is as follows Copy Code

function Flower (): Sprite {
var mc:sprite=new Sprite ();
var color:uint=math.random () *0x88ffff+0x880000;
var num:int=int (Math.random () *9+1);
var i:int=0;
while (I++<num) {
var huaban:shape=new Shape ();
HuaBan.graphics.beginGradientFill (gradienttype.radial,[0xffffff,color],[0.6,1],[0,255]);
HuaBan.graphics.moveTo (0,0);
HuaBan.graphics.curveTo (30,-45,0,-50);
HuaBan.graphics.curveTo ( -30,-45,0,0);
Huaban.rotation=360/num*i;
Mc.addchild (Huaban);
}
return MC;
}
Drawing Flower Function//www.111cn.net
Number of Var mcnum:int=50;//flowers
var mcarr:array=[];//stores the array of flowers
var vxarr:array=[];//x speed Array
var vyarr:array=[];//y speed Array
var vrarr:array=[];//rotational speed Array
var clickcount:int=0;//click Times
for (var i:int=0; i<mcnum; i++) {
var mc:sprite=flower ();
AddChild (MC);
Mc.scalex=mc.scaley=0.2+math.random () *0.5;
Mc.x=math.random () *stage.stagewidth;
Mc.y=-math.random () *stage.stageheight;
Vxarr.push (Math.random () *2-1);
Vyarr.push (Math.random () *2+2);
Vrarr.push (Math.random () *4-2);
Mcarr.push (MC);
}
AddEventListener (Event.enter_frame,frame);
function frame (e:event): void {
For (i=0 i<mcnum; i++) {
Mcarr[i].x+=vxarr[i];
Mcarr[i].y+=vyarr[i];
Mcarr[i].rotation+=vrarr[i];
if (MCARR[I].Y&GT;STAGE.STAGEHEIGHT+MCARR[I].WIDTH/2) {
Mcarr[i].x=math.random () *stage.stagewidth;
Mcarr[i].y=-math.random () *stage.stageheight;
}
}
}
Stage.addeventlistener (Mouseevent.click,onclick);
function OnClick (e:mouseevent): void {
if (clickcount++%2==0) {
RemoveEventListener (Event.enter_frame,frame);
} else {
AddEventListener (Event.enter_frame,frame);
}
}

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.