添加皮肤后,按钮上的标签消失

时间:2012-08-24 07:39:47

标签: actionscript-3 flash-builder

我设置了按钮的标签和皮肤但是当我尝试添加代码来随机化皮肤时,皮肤工作正常,但标签消失了。如果我删除button1.setStyle(“skinClass”,randomSkin());标签显示。

public function randomSkin():Class{
var randSkin:Array = new Array(Skins.Normal,Skins.Ice,Skins.Fire,Skins.Jewel,Skins.Stone);
var index:Number=Math.floor(Math.random()*randSkin.length);
return randSkin[index];
}

button1.setStyle("skinClass", randomSkin());
button1.label=tiles[0][0];

当我尝试跟踪按钮的标签时,它有一个值,但它没有显示在按钮上。

如何在按钮上显示标签?

这是我使用过的皮肤代码之一

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    width.down="100%" height.down="100%">
<!-- host component -->
<fx:Metadata>
    [HostComponent("spark.components.Button")]
</fx:Metadata>

<!-- states -->
<s:states>
    <s:State name="disabled" />
    <s:State name="down" />
    <s:State name="over" />
    <s:State name="up" />
</s:states>
<s:BitmapImage includeIn="disabled" left="0" right="0" top="0" bottom="0"
         source="@Embed('assets/textures/tiles/fire.png')"/>
<s:BitmapImage includeIn="down" left="0" right="0" top="0" bottom="0" blendMode="difference"
         source="@Embed('assets/textures/tiles/fire.png')"/>
<s:BitmapImage includeIn="over" left="0" right="0" top="0" bottom="0"
         source="@Embed('assets/textures/tiles/fire.png')"/>
<s:BitmapImage includeIn="up" left="0" right="0" top="0" bottom="0"
         source="@Embed('assets/textures/tiles/fire.png')"/>
<s:Group id="contentGroup" top="52" left="5" right="5"/>

</s:Skin>

1 个答案:

答案 0 :(得分:0)

你的皮肤上没有标签,这就是它没有显示的原因。使用属性id="labelDisplay"添加它。你可以从sdk检查皮肤代码:

<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
             xmlns:s="library://ns.adobe.com/flex/spark" 
             minWidth="21" minHeight="21"
             alpha.disabled="0.5">

    <fx:Metadata>
        <![CDATA[
            [HostComponent("spark.components.Button")]
        ]]>
    </fx:Metadata>

    <s:states>
        <s:State name="up" />
        <s:State name="over" />
        <s:State name="down" />
        <s:State name="disabled" />
    </s:states>

    <s:Rect excludeFrom="over, down, disabled" left="0" top="0" right="0" bottom="0" radiusX="2" >
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="0xf3f4f9"
                                 ratio="0"/>
                <s:GradientEntry color="0xf3f4f9"
                                 ratio="0.16"/>
                <s:GradientEntry color="0xdee5f3"
                                 ratio="0.60"/>
                <s:GradientEntry color="0xd4dbe8"
                                 ratio="1"/>
            </s:LinearGradient>
        </s:fill>
        <s:stroke>
            <s:SolidColorStroke color="0xbbbbbb"/>
        </s:stroke>
    </s:Rect>

    <s:Rect includeIn="over, down" left="0" top="0" right="0" bottom="0" radiusX="2" >
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="0xffffe3"
                                 ratio="0"/>
                <s:GradientEntry color="0xfff18c"
                                 ratio="0.45"/>
                <s:GradientEntry color="0xffdd5d"
                                 ratio="0.52"/>
                <s:GradientEntry color="0xffeb92"
                                 ratio="1"/>
            </s:LinearGradient>
        </s:fill>
        <s:stroke>
            <s:SolidColorStroke color="0xbbbbbb"/>
        </s:stroke>
    </s:Rect>

    <s:Rect includeIn="disabled" left="0" top="0" right="0" bottom="0" radiusX="2" >
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="0xf3f4f9"
                                 ratio="0"/>
                <s:GradientEntry color="0xdddddd"
                                 ratio="0.75"/>
                <s:GradientEntry color="0xdddddd"
                                 ratio="1"/>
            </s:LinearGradient>
        </s:fill>
        <s:stroke>
            <s:SolidColorStroke color="0xbbbbbb"/>
        </s:stroke>
    </s:Rect>

    <s:Label id="labelDisplay"
             width="100%" height="100%"
             textAlign="center"
             verticalAlign="middle"
             maxDisplayedLines="1">
    </s:Label>

</s:SparkSkin>