Flash AS实例:随风飘摆的大红灯笼

http://www.webjx.com/  2010-03-19 02:08:03  来源:中国教程网论坛 作者:zctmh0336(诚信为人

Webjx核心提示:全脚本绘制:大红灯笼高高挂.

 灯笼——全脚本绘制,先看绘制效果:


详细代码:


[SWF(backgroundColor=0x004890,width=550,height=400)]

var denglong:MovieClip =new MovieClip();

addChild(denglong);

denglong.x=275;

denglong.y=0;

denglong.rotation=5;

var rota:Number=0;

denglong.addEventListener(Event.ENTER_FRAME ,frame);

function frame(e) {

        var xs:Number=(0-denglong.rotation)*0.01;

        rota+=xs;

        denglong.rotation+=rota;

}

var diaoxian:Shape =new Shape();

denglong.addChild(diaoxian);

diaoxian.graphics.lineStyle(6, 0xcc6600);

diaoxian.graphics.moveTo(0,0);

diaoxian.graphics.lineTo(0,50);

function Rect():Sprite {

        var sp:Sprite =new Sprite();

        sp.graphics.beginGradientFill("linear" ,[0xffbe17,0xf8fd97,0xffbe17],[1,1,1],[0,128,255]);

        sp.graphics.drawRoundRect(-50,-10,100,20,15,13);

        var mc:Shape=new Shape();

        sp.addChild(mc);

        mc.graphics.lineStyle(1.5,0x996633,1);

        mc.graphics.drawRoundRect(-48,-9,96,18,13,12);

        return sp;

}

for (var c:int=0; c<4; c++) {

        var rect:Sprite=Rect();

        denglong.addChild(rect);

        c%2==0?[rect.scaleX=rect.scaleY=0.7,rect.y=50+c*107]:rect.y=c*90-23;

}

function Huxian(n:int):Shape {

        var hu:Shape=new Shape();

        hu.graphics.beginFill(0xffbe17,1);

        hu.graphics.moveTo(0,0);

        hu.graphics.curveTo(n,80,0,160);

        hu.graphics.curveTo(n+5,80,0,0);

        return hu;

}

var ellip:Sprite=new Sprite();

denglong.addChildAt(ellip,0);

ellip.y=158;

ellip.graphics.beginGradientFill("radial" ,[0xfea408,0xe20708],[1,1],[0,255]);

ellip.graphics.drawEllipse(-120,-85,240,170);

for (var d:int=0; d<4; d++) {

        var n:int;

        var huxian:Shape=Huxian(d%4==0?n=-80:d%4==1?n=-60:d%4==2?n=60:d%4==3?n=80:0);

        ellip.addChild(huxian);

        huxian.x=-45+d*30;

        huxian.y=-80;

}

function line():Sprite {

        var sp:Sprite =new Sprite();

        sp.graphics.lineStyle(0.5,0xffff00,1);

        sp.graphics.moveTo(0,0);

        sp.graphics.lineTo(0,60);

        return sp;

}

for (var a:int=0; a<15; a++) {

        var mc:Sprite=line();

        denglong.addChild(mc);

        mc.x=a*4-28;

        mc.y=270;

}
更多