Flex4: if I want different icons, should I create a skin class for each button?

佐手、 提交于 2020-01-15 12:11:11

问题


i have a sequence of buttons and each button has its own icon. I was wondering if I have to create a Spark skin file for each button in order to assign its icon.

thanks


回答1:


You don't have to create separate skins, you could make 1 skin and 1 class (that extends Button) with a property you can set to determine which icon to draw based on the button.

You can extend the button class like this

package com.components
{
    import spark.components.Button;     

    //icons
    [Style(name="iconImg",type="*")]

    public class IconButton extends Button
    {
        public function IconButton()
        {
            super();
        }
    }
}

At this point you'd have a set of IconButtons and you'd need to set the iconImg property for each.

Declare the icon

[Embed('assets/bookmarkIcon.png')]
public static const icon_bookmark:Class;

And the set the iconImg property

<components:IconButton id="ibBookmark"
               iconImg="{icon_bookmark}"
               skinClass="com.skins.IconButtonSkin"                        
               click="" /> 

Then in your skin you use the property like this

<mx:Image id="icon" source="{hostComponent.getStyle('iconImg')}"  />


来源:https://stackoverflow.com/questions/2974518/flex4-if-i-want-different-icons-should-i-create-a-skin-class-for-each-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!