椭圆形按钮的代码

类别:编程语言 点击:0 评论:0 推荐:

//**************************************************************************** // ______ // .-" "-. // / AOL \ // | | // |, .-. .-. ,| // | )(__/ \__)( | // |/ /\ \| // (@_ (_ ^^ _) // _ ) \_______\__|IIIIII|__/__________________________ // (_)@8@8{}<________|-\IIIIII/-|___________________________> // )_/ \ / // (@ `--------` AOL FLASH STUDIO. //**************************************************************************** // @FileName OvalButtonSkin.as // @Package // @Description 椭圆按钮皮肤 // @Author aol // @Email [email protected] // @Create 2004.08.27 // @LastChange 2004.08.27 // @History //**************************************************************************** import mx.skins.RectBorder; import mx.skins.SkinElement; import mx.core.ext.UIObjectExtensions; class OvalButtonSkin extends RectBorder { /** @private * SymbolName for object */ static var symbolName:String = "OvalButtonSkin"; /** @private * Class used in createClassObject */ static var symbolOwner:Object = OvalButtonSkin; /** * name of this class */ var className = "OvalButtonSkin"; var backgroundColorName = "buttonColor"; //var drawOval:Function; function OvalButtonSkin() { } function init():Void { super.init(); } function size():Void { drawHaloRect(width,height); } function drawHaloRect(w:Number,h:Number):Void { var borderStyle = getStyle("borderStyle"); var themeCol = getStyle("themeColor"); var emph:Boolean = _parent.emphasized; clear(); switch (borderStyle) { case "falseup": if (emph) { drawOval( x,y,w,h,0x919999,100);//OuterBorder drawOval( x,y,w,h,themeCol,75);//OuterBorder drawOval( x+1,y+1,w-2,h-2,[0x333333,0xffffff],85,0,"radial"); drawOval( x+2,y+2,w-4,h-4,[0x000000,0xdadada],100,0,"radial"); drawOval( x+2,y+2,w-4,h-4,themeCol,75); drawOval( x+3,y+3,w-6,h-6,0xffffff,100);//highlight drawOval( x+3,y+4,w-6,h-7,0xf8f8f8,100);//face } else { drawOval( 0,0,w,h,0x919999,100);//OuterBorder drawOval( 1,1,w-2,h-2,[0xcad1d1,0xf7f7f7],100,0,"radial"); drawOval( 2,2,w-4,h-4,[0x919999,0xd2dada],100,0,"radial"); drawOval( 3,3,w-6,h-6,0xffffff,100);//highlight drawOval( 4,4,w-6,h-7,0xf8f8f8,100);//face } break; case "falsedown": drawOval( x,y,w,h,0x919999,100);//OuterBorder drawOval( x+1,y+1,w-2,h-2,[0x333333,0xfcfcfc],100,0,"radial"); drawOval( x+1,y+1,w-2,h-2,themeCol,50); drawOval( x+2,y+2,w-4,h-4,[0x000000,0xdadada],100,0,"radial"); drawOval( x,y,w,h,themeCol,40);//OuterBorder drawOval( x+3,y+3,w-6,h-6,0xffffff,100);//highlight drawOval( x+3,y+4,w-6,h-7,themeCol,20);//face break; case "falserollover": drawOval( x,y,w,h,0x919999,100);//OuterBorder drawOval( x,y,w,h,themeCol,50);//OuterBorder drawOval( x+1,y+1,w-2,h-2,[0x333333,0xffffff],100,0,"radial"); drawOval( x+2,y+2,w-4,h-4,[0x000000,0xdadada],100,0,"radial"); drawOval( x+2,y+2,w-4,h-4,themeCol,50); drawOval( x+3,y+3,w-6,h-6,0xffffff,100);//highlight drawOval( x+3,y+4,w-6,h-7,0xf8f8f8,100);//face break; case "falsedisabled": drawOval( 0,0,w,h,0xc8cccc,100);//OuterBorder drawOval( 1,1,w-2,h-2,0xf2f2f2,100); drawOval( 2,2,w-4,h-4,0xd4d9d9,100); drawOval( 3,3,w-6,h-6,0xf2f2f2,100);//face break; case "trueup": drawOval( x,y,w,h,0x999999,100);//OuterBorder drawOval( x+1,y+1,w-2,h-2,[0x333333,0xfcfcfc],100,0,"radial"); drawOval( x+1,y+1,w-2,h-2,themeCol,50); drawOval( x+2,y+2,w-4,h-4,[0x000000,0xdadada],100,0,"radial"); drawOval( x,y,w,h,themeCol,40);//OuterBorder drawOval( x+3,y+3,w-6,h-6,0xffffff,100);//highlight drawOval( x+3,y+4,w-6,h-7,0xf7f7f7,100);//face break; case "truedown": drawOval( x,y,w,h,0x999999,100);//OuterBorder drawOval( x+1,y+1,w-2,h-2,[0x333333,0xfcfcfc],100,0,"radial"); drawOval( x+1,y+1,w-2,h-2,themeCol,50); drawOval( x+2,y+2,w-4,h-4,[0x000000,0xdadada],100,0,"radial"); drawOval( x,y,w,h,themeCol,40);//OuterBorder drawOval( x+3,y+3,w-6,h-6,0xffffff,100);//highlight drawOval( x+3,y+4,w-6,h-7,themeCol,20);//face break; case "truerollover": drawOval( x,y,w,h,0x919999,100);//OuterBorder drawOval( x,y,w,h,themeCol,50);//OuterBorder drawOval( x+1,y+1,w-2,h-2,[0x333333,0xffffff],100,0,"radial"); drawOval( x+1,y+1,w-2,h-2,themeCol,40); drawOval(x+2,y+2,w-4,h-4,[0x000000,0xdadada],100,0,"radial"); drawOval( x+2,y+2,w-4,h-4,themeCol,40); drawOval( x+3,y+3,w-6,h-6,0xffffff,100);//highlight drawOval( x+3,y+4,w-6,h-7,0xf8f8f8,100);//face break; case "truedisabled": drawOval( 0,0,w,h,0xc8cccc,100);//OuterBorder drawOval( 1,1,w-2,h-2,0xf2f2f2,100); drawOval( 2,2,w-4,h-4,0xd4d9d9,100); drawOval( 3,3,w-6,h-6,0xf2f2f2,100);//face } } function drawOval(x0:Number, y0:Number, w:Number, h:Number,c,alpha:Number,rot:Number,grad:String) { var radius = w/2; var yRadius = h/2; var x = x0+radius; var y = y0+yRadius; if (arguments.length < 3) { return; } if(typeof c == "object"){ var alphas = [alpha,alpha]; var ratios = [ 0, 0xff ]; var sh = h *.7 var matrix = {matrixType:"box", x:-sh, y:sh, w:w*2, h:h*4, r:rot * 0.0174532925199433 } if (grad == "radial"){ this.beginGradientFill( "radial", c, alphas, ratios, matrix ); }else{ this.beginGradientFill( "linear", c, alphas, ratios, matrix ); } }else if (c != undefined) { this.beginFill (c, alpha); } // init variables var theta:Number, xrCtrl:Number, yrCtrl:Number, angle:Number, angleMid:Number; var px:Number, py:Number, cx:Number, cy:Number; // if only yRadius is undefined, yRadius = radius if (yRadius == undefined) { yRadius = radius; } // covert 45 degrees to radians for our calculations theta = Math.PI / 4; // calculate the distance for the control point xrCtrl = radius / Math.cos(theta / 2); yrCtrl = yRadius / Math.cos(theta / 2); // start on the right side of the circle angle = 0; this.moveTo(x + radius, y); // this loop draws the circle in 8 segments for (var i = 0; i < 8; i++) { // increment our angles angle += theta; angleMid = angle - (theta / 2); // calculate our control point cx = x + Math.cos(angleMid) * xrCtrl; cy = y + Math.sin(angleMid) * yrCtrl; // calculate our end point px = x + Math.cos(angle) * radius; py = y + Math.sin(angle) * yRadius; // draw the circle segment this.curveTo(cx, cy, px, py); } if (c != undefined) this.endFill(); }; static function classConstruct():Boolean { UIObjectExtensions.Extensions(); _global.skinRegistry["OvalButtonSkin"] = true; return true; } static var classConstructed:Boolean = classConstruct(); static var UIObjectExtensionsDependency = UIObjectExtensions; } 这里有一个缺点,就是一旦改变了组件的主题,就不能在同一个fla文件中使用另外一种主题的组件.因为它们是由
一个全局变量来控制.目前我只能用setStyle()和另做一个组件来使它们能够共存.macromedia在整体的组件设计上
是有很多缺陷的,不光在这里.在基类的设计上,还有事件模型的设计上都有一些重大的缺陷.有时间自己用MVC模式设计一套吧.

本文地址:http://com.8s8s.com/it/it27852.htm