2012-06-29 256 views
2

以下代碼,我實現了圖像更改。 但是圖像名稱是硬編碼的,在樣式中指定。如何使它參數化?我想重新使用這個小圖標名稱作爲輸入參數。 所有使用的圖像(我的情況是14張圖像)將包含在flex項目中。 我使用Flex 3的flex,當鼠標懸停在按鈕上時,更改鼠標懸停/跳出時的按鈕圖像

<mx:Style> 
    .myCustomButton { 
     upSkin: Embed(source="jjyxfx.png"); 
     overSkin:Embed(source="cwgl.png"); 
     downSkin: Embed(source="cwgl.png"); 

    } 
</mx:Style> 

<mx:Button y="0" width="105" height="107" fillAlphas="[1.0, 1.0, 1.0, 1.0]" x="0" fillColors="[#3AA2D9, #3AA2D9]" styleName="myCustomButton" useHandCursor="true" buttonMode="true"/> 

回答

0

我不相信你不能參數CSS樣式;所以你必須通過ActionScript設置樣式:

public function setStylesOnButton(upSkinValue:String,overSkinValue:String,downSkinStyle:String):void{ 
    myButton.setStyle('upSkin',upSkinValue); 
    myButton.setStyle('overSkin',overSkinValue); 
    myButton.setStyle('downSkin',downSkinStyle); 
} 

確保您的按鈕有一個ID,因此您可以在ActionScript訪問它,因爲他們回覆

<mx:Button id="myButton" y="0" width="105" height="107" fillAlphas="[1.0, 1.0, 1.0, 1.0]" x="0" fillColors="[#3AA2D9, #3AA2D9]" styleName="myCustomButton" useHandCursor="true" buttonMode="true"/> 
+0

感謝。什麼值(upskinValue)看起來像?我嘗試了一些,但他們都沒有工作 –

+0

我不明白你的問題。您在原始CSS中設置upSkinValue。它是一個字符串。這是沒有不同的設置,我提供的代碼中的值。 – JeffryHouser