换肤链接按钮

时间:2013-12-17 06:44:02

标签: actionscript-3 flex actionscript flex4

这是我修改过的代码。在这里,我给了皮肤类&选择颜色。

最新代码

<mx:LinkButton label="home" styleName="Helvetica22555555" id="homeBtn" fontSize="14" color="#ffffff"
                       useHandCursor="true" buttonMode="true" 
                       skin="{com.firstplanet.utils.ULinkButtonSkin}" toggle="true" selectionColor="0xC0D3E2"/>
        <mx:LinkButton label="course" styleName="Helvetica22555555" id="link"  fontSize="14" color="#ffffff"
                       skin="{com.firstplanet.utils.ULinkButtonSkin}" selectionColor="0xC0D3E2"/>
        <mx:LinkButton label="dashboard" styleName="Helvetica22555555" fontSize="14" color="#ffffff"
                       skin="{com.firstplanet.utils.ULinkButtonSkin}" toggle="true" selectionColor="0xC0D3E2"/>
        <mx:LinkButton label="logout" styleName="Helvetica22555555" fontSize="14" color="#ffffff"
                       useHandCursor="true" buttonMode="true"
                       skin="{com.firstplanet.utils.ULinkButtonSkin}" toggle="true" selectionColor="0xC0D3E2"/>

和我在下面使用的皮肤类

 package com.firstplanet.utils
 {
import mx.skins.halo.LinkButtonSkin;

public class ULinkButtonSkin extends LinkButtonSkin
{
    public function ULinkButtonSkin()
    {
        super();
    }

    override protected function updateDisplayList(w:Number, h:Number):void
    {
        var cornerRadius:Number = getStyle("cornerRadius");
        var selectionColor:uint = getStyle("selectionColor");
        graphics.clear();

        switch (name)
        {           
            case "selectedUpSkin":
            case "selectedOverSkin":
            case "selectedDownSkin":
            {
                drawRoundRect(0, 0, w, h, cornerRadius, selectionColor, 1);
                break;
            }
            default:
            {
                super.updateDisplayList(w, h);
                break;
            }
        }
    }
}
}

但它不起作用。如果我选择一个按钮,那么其他按钮也会突出显示。

1 个答案:

答案 0 :(得分:0)

用法:

<local:ULinkButton label="Red Link Button" skin="ULinkButtonSkin" toggle="true" selectionColor="0xFF0000"/>

改变背景颜色的皮肤:

package
{
import mx.skins.halo.LinkButtonSkin;

public class ULinkButtonSkin extends LinkButtonSkin
{
    public function ULinkButtonSkin()
    {
        super();
    }

    override protected function updateDisplayList(w:Number, h:Number):void
    {
        var cornerRadius:Number = getStyle("cornerRadius");
        var selectionColor:uint = getStyle("selectionColor");
        graphics.clear();

        switch (name)
        {           
            case "selectedUpSkin":
            case "selectedOverSkin":
            case "selectedDownSkin":
            {
                drawRoundRect(0, 0, w, h, cornerRadius, selectionColor, 1);
                break;
            }
            default:
            {
                super.updateDisplayList(w, h);
                break;
            }
        }
    }
}
}