简体   繁体   中英

flex, change the button image when mouse over/out

with following code, i have implemented the image change when mouse hover the button. but the image name is hardcoded, which is specified in the style. how can make it parameterized? i want to reuse this small utility with image name as input parameter. all the image used(14 images in my case) will be included in the flex project. i am using 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"/>

I don't believe you can't parameterize CSS styles; so you'll have to set the styles via ActionScript:

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

Make sure your button has an ID so you can access it in 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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM