Flex AS3 - 自定义按钮

时间:2012-05-21 12:12:03

标签: actionscript-3 flex button

我需要一些输入.. 在Flash Builder中实现自定义按钮的最佳(推荐)方法是什么?

我的意思是自定义按钮,我需要展示一个有5层楼的建筑物(在3d视图中)。然后,用户可以单击每个楼层,以更新主视图以显示当前选定的楼层。

在前面的例子中,我只是在图像下方添加了一个不可见的图层,每个按钮(每个图层)包含一个纯色。单击图像会触发一个功能,该功能会检查选择的颜色,然后触发我想要的操作。

有没有更好的方法呢?

也许导入与主应用程序通信的外部SWF以发送楼层切换命令? (不是我知道如何从导入的外部SWF到主应用程序进行通信,只是相反)。

任何输入都会很棒=)

谢谢!

3 个答案:

答案 0 :(得分:3)

修改

在你的问题之后,我迅速掀起了一些东西,表明按钮可以是任何形状。如果您希望地板可以选择,那么您可能需要ToggleButton,而不是Button,所以我重新修改了我的示例,结果就是您所描述的

enter image description here

为什么不使用Flex 4.0 Skinning功能?您可以使用自己的外观获得按钮组件的行为(和状态):

<s:ToggleButton skinClass="FloorButton" y="0"  />
<s:ToggleButton skinClass="FloorButton" y="25" />
<s:ToggleButton skinClass="FloorButton" y="50" />

使用一些图像定义按钮外观(FloorButton):

<?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
                   alpha.disabledStates="0.5">

    <fx:Metadata>
    <![CDATA[ 
        [HostComponent("spark.components.ToggleButton")]
    ]]>
    </fx:Metadata>

    <s:states>
        <s:State name="up" />
        <s:State name="over" stateGroups="overStates" />
        <s:State name="down" stateGroups="downStates" />
        <s:State name="disabled" stateGroups="disabledStates" />
        <s:State name="upAndSelected" stateGroups="selectedStates, selectedUpStates" />
        <s:State name="overAndSelected" stateGroups="overStates, selectedStates" />
        <s:State name="downAndSelected" stateGroups="downStates, selectedStates" />
        <s:State name="disabledAndSelected" stateGroups="selectedUpStates, disabledStates, selectedStates" />
    </s:states>

    <s:Path data="M 0 0 L 20 20 L 40 0 L 40 20 L 20 40 L 0 20">
        <s:fill>
            <s:SolidColor color="#AAAAAA" color.selectedStates="#000000" color.over="#777777" />
        </s:fill>
    </s:Path>

</s:SparkButtonSkin>

当然,路径可以用具有透明度的PNG替换以实现类似的效果。

答案 1 :(得分:0)

当你使用flex时,为什么不使用flex组件并对它们进行修饰?

答案 2 :(得分:0)

关于如何在Flex 4中进行按钮蒙皮的

This教程将逐步完成整个过程。

Flex 4还支持易于实施3d effects(您在问题中提到过)。