【问题标题】:flex, change the button image when mouse over/outflex,鼠标悬停/移出时更改按钮图像
【发布时间】:2012-06-29 06:30:04
【问题描述】:

使用以下代码,我已经实现了鼠标悬停按钮时的图像更改。 但是图像名称是硬编码的,在样式中指定。如何使其参数化?我想重用这个以图像名称作为输入参数的小实用程序。 所有使用的图像(在我的例子中是 14 个图像)都将包含在 flex 项目中。 我正在使用 flex 3

<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"/>

【问题讨论】:

    标签: image apache-flex button


    【解决方案1】:

    我不相信你不能参数化 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"/>
    

    【讨论】:

    • 感谢他们的回复。价值(upskinValue)是什么样的?我尝试了一些,但它们都不起作用
    • 我不明白你的问题。您在原始 CSS 中设置了 upSkinValue。它是一个字符串。在我提供的代码中设置该值没有什么不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 2011-10-24
    • 2014-05-31
    • 2010-11-30
    相关资源
    最近更新 更多