论坛首页 编程语言技术论坛

关于Flex背景渐变和皮肤动态切换的补丁

浏览 2725 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-10-27  
网上有代码可以实现背景渐变,但是在style动态切换的时候无效。
我hack了setupStyles()处的代码,可以使用了。

注意设置fillColors是十进制的颜色值。
比如:css = ".selector{fillColors: 12377400,9614128;}";

package application.view.components
{
	
	import flash.display.*;
	import flash.geom.*;
	import flash.utils.*;
	
	import mx.containers.Canvas;
	import mx.core.EdgeMetrics;
	import mx.skins.halo.HaloBorder;
	import mx.utils.ColorUtil;
	import mx.utils.GraphicsUtil;
	
	public class SimpleGradientBorder extends HaloBorder 
	{
		
		private var topCornerRadius:Number;		// top corner radius
		private var bottomCornerRadius:Number;	// bottom corner radius
		private var fillColors:Array;			// fill colors (two)
		private var setup:Boolean;
		
		// ------------------------------------------------------------------------------------- //
		
		private function setupStyles():void
		{
			if ((this.parent as Canvas) != null)
			{
				var str:String = (this.parent as Canvas).getStyle("fillColors");
				fillColors = str.split(",");
			}
			else
			{
				fillColors = getStyle("fillColors") as Array;
			}
			if (!fillColors) fillColors = [0xFFFFFF, 0xFFFFFF];
			
			topCornerRadius = getStyle("cornerRadius") as Number;
			if (!topCornerRadius) topCornerRadius = 0;	
			
			bottomCornerRadius = getStyle("bottomCornerRadius") as Number;
			if (!bottomCornerRadius) bottomCornerRadius = topCornerRadius;	
		
		}
		
		// ------------------------------------------------------------------------------------- //
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);	
			
			setupStyles();
			
			var g:Graphics = graphics;
			var b:EdgeMetrics = borderMetrics;
			var w:Number = unscaledWidth - b.left - b.right;
			var h:Number = unscaledHeight - b.top - b.bottom;
			var m:Matrix = verticalGradientMatrix(0, 0, w, h);
		
			g.beginGradientFill("linear", fillColors, [1, 1], [0, 255], m);
			
			var tr:Number = Math.max(topCornerRadius-2, 0);
			var br:Number = Math.max(bottomCornerRadius-2, 0);
			
			GraphicsUtil.drawRoundRectComplex(g, b.left, b.top, w, h, tr, tr, br, br);
			g.endFill();
				
		}
		
	}
}
   发表时间:2011-02-13  
能给个全代码么?看不明白呀
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics