【问题标题】:Why is this Flex 4 Transition not working?为什么此 Flex 4 过渡不起作用?
【发布时间】:2011-05-17 14:58:13
【问题描述】:

我有一个测试应用程序here,它是使用以下代码制作的:

<fx:Script>
    <![CDATA[

            public function comboBoxHandler():void{
                var selectedItem:String = showComboBox.selectedItem;

                if(selectedItem == "All results"){
                    currentState = "default";
                    return;
                }else if(selectedItem == "Only results within tags"){
                    currentState = "tagInput";
                    return;
                }
            }

    ]]>
</fx:Script>    
<s:states>
    <s:State name="default"/>
    <s:State name="tagInput"/>
</s:states>
<s:transitions>
    <s:Transition id="showTagTextInput" fromState="default" toState="tagInput">
        <s:Sequence id="t1p1" targets="{[tagsLabel,tagsTextInput,GoButton]}">

            <s:Move  duration="700"/>
            <s:Fade  duration="400"/>

        </s:Sequence>
    </s:Transition>
    <s:Transition id="hideTagTextInput" fromState="tagInput" toState="default">
        <s:Sequence id="t2p1" targets="{[tagsLabel,tagsTextInput,GoButton]}" >

            <s:Fade  duration="400"/>
            <s:Move  duration="700"/>

        </s:Sequence>
    </s:Transition>

</s:transitions>

<s:Label x="136" y="13" width="120" height="34" fontFamily="Arial" fontSize="15"
             text="Lessons&#xd;Learnt" textAlign="center"/>

    <s:Group id="group" width="100%" height="100%"
             x.default="0" y.default="55" width.default="400" height.default="231"
             y.tagInput="55" height.tagInput="256">
        <s:Label x="45" y="38" width="50" height="22" text="Search" textAlign="center"
                 verticalAlign="middle"/>
        <s:TextInput x="103" y="38" width="193"
                     useHandCursor.tagInput="false"/>
        <s:Label x="45" y="89" width="51" height="22" text="Show" textAlign="center"
                 verticalAlign="middle"/>
        <s:Button id="GoButton" x="253" y="137" width="43" label="Go" useHandCursor="true"
                  buttonMode="true" mouseChildren="false"
                  x.tagInput="254" y.tagInput="188"/>
        <s:DropDownList id="showComboBox" x="104" y="89" width="192" change="comboBoxHandler();"
                    selectedIndex="0">
            <s:ArrayCollection>
                <fx:String>All results</fx:String>
                <fx:String>Only results within tags</fx:String>
            </s:ArrayCollection>
        </s:DropDownList>
        <s:Label id="tagsLabel" includeIn="tagInput" x="104" y="146" width="61" height="20" text="Tags"
                 textAlign="center" verticalAlign="middle"/>
        <s:TextInput id="tagsTextInput" includeIn="tagInput" x="173" y="146" width="123"/>

    </s:Group>

您可以通过单击我提供的链接检查,当您从 DropDownBox 中选择不同的选项时,此应用程序会执行一些基本的过渡效果。

第一个(显示)过渡效果不太好,但第二个(隐藏)过渡效果很好。

有谁知道如何解决这个问题?在第一次转换中,我希望按钮向下滑动,然后文本输入才会淡入。 为什么这不起作用?

提前致谢。

【问题讨论】:

  • 你能展示你所有的代码吗?我认为问题出在状态/组件默认值上。

标签: apache-flex flex4 mxml flex-spark


【解决方案1】:

最好指向特定的效果目标,而不是指向&lt;s:Sequence /&gt;中的所有目标。所以将目标放在&lt;s:Move /&gt;&lt;s:Fade /&gt;。此外,您还可以通过将 &lt;s:AddAction /&gt;&lt;s:RemoveAction /&gt; 与相应的目标放在序列中的一个位置来执行额外的转换调整,在该位置转换应该调用 includeInexcludeFrom 状态声明。

所以这些转换适用于您的代码:

<s:transitions>
    <s:Transition fromState="default" id="showTagTextInput" toState="tagInput">
        <s:Sequence id="t1p1">
            <s:Move duration="700" targets="{[GoButton]}" />
            <s:AddAction targets="{[tagsLabel,tagsTextInput]}" />
            <s:Fade duration="400" targets="{[tagsLabel,tagsTextInput]}" />
        </s:Sequence>
    </s:Transition>
    <s:Transition fromState="tagInput" id="hideTagTextInput" toState="default">
        <s:Sequence id="t2p1">
            <s:Fade duration="400" targets="{[tagsLabel,tagsTextInput]}" />
            <s:RemoveAction targets="{[tagsLabel,tagsTextInput]}" />
            <s:Move duration="700" targets="{[GoButton]}" />
        </s:Sequence>
    </s:Transition>
</s:transitions>

【讨论】:

  • 我同意在实际行动中传播目标。但是当我明确定义我希望转换发生的顺序时,我不太明白为什么这段代码不起作用。我不明白为什么显示的代码没有产生预期的效果。
  • 工作得很好...非常感谢。
【解决方案2】:

我想这是因为您的标签输入仅包含在 tagInput 状态中,但 alpha 为 100%,并且状态之间没有转换。试试这个:

<s:Label id="tagsLabel" alpha.default="0" alpha.tagInput="100" x="104" y="146" width="61" height="20" text="Tags" textAlign="center" verticalAlign="middle"/>
<s:TextInput id="tagsTextInput" alpha.default="0" alpha.tagInput="100" x="173" y="146" width="123"/>

您可能还希望在“默认”状态下将可见设置为 false。还有,康斯坦丁说的是真的。

【讨论】:

    猜你喜欢
    • 2013-10-25
    • 1970-01-01
    • 2013-03-03
    • 2018-08-26
    • 1970-01-01
    • 2013-10-20
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多