2012-08-24 39 views
0

我設置標籤和按鈕的皮膚,但是當我嘗試添加代碼,以隨機的皮膚,使皮膚工作得很好,但標籤消失。如果我刪除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> 
+0

please,顯示其中一個皮膚代碼 –

+0

cnt發表評論中的代碼。請參見上面的編輯問題。謝謝 – Mirage01

回答

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>