Skip to main content

Posts

Showing posts from March, 2009

[Flex] Button enabled=false 自動灰階

嗯...這只是一個懶人小技巧,為了就是省下作 Button enaqbled=false 時的灰階 Icon 圖...( 這個作法是將 disable 狀態直接都變成灰階的...所以設 disable 文字顏色也沒用喔...XD )
原理蠻簡單的就是 override 掉 updateDisplayList 這個 function ( override enabled setter 也可行)

/*
LazyButton
Copyright (c) 2009 Erin Lin ( Yu-Shan Lin)
Your reuse is governed by the Creative Commons Attribution 3.0 License
最近大家都很愛寫CC license 所以我也來寫一下...XD
enabled = false; 變灰階
*/
package
{
import mx.controls.Button;
import flash.filters.ColorMatrixFilter;

public class LazyButton extends Button
{
public function LazyButton()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(!enabled){
filters = [new ColorMatrixFilter(
[0.3086,0.6094,0.0820,0,0,
0.3086,0.6094,0.0820,0,0,
0.3086,0.6094,0.0820,0,0,
0,0,0,1,0])];
}else{
filters = [];
}
}
}
}