【问题标题】:State Transitions in FlexFlex 中的状态转换
【发布时间】:2010-01-11 16:39:16
【问题描述】:

我有一个具有 2 个状态的 flex 组件——“”(即没有名称/默认值)和“事务性”——以及一组从一个状态移动到另一个状态的转换。

有一个按钮可以在两种状态之间切换,点击时会调用以下函数

public function ToggleState():void
{
    if (this.currentState=="Transactional")
    {
        this.currentState = "";
    }
    else
    {
        this.currentState = "Transactional";
    }

}

除非您在组件从一种状态更改为另一种状态时单击按钮,否则一切都会按预期进行。在那之后事情开始变得奇怪 - 一些以前会淡出的组件不再消失。其他人不再出现

我怀疑这是因为转换没有正确完成,因此动画组件的属性没有正确重置为正确的值。

我尝试进行一些检查以判断状态是否正在改变(因此在播放过渡时禁用按钮),但我能找到的唯一要监听的事件是

enterState
currentStateChange
currentStateChanging

所有这些都在转换完成之前触发。

有没有人知道任何其他适合监听的事件或更好的状态更改方法?

更新:

这是我用于转换的 mxml

<transitions>
    <mx:Transition fromState="" toState="Transactional">
        <mx:Sequence>
            <mx:Parallel>
                <mx:AnimateProperty target="{Controller}" property="y" fromValue="-60" toValue="-1" duration="600" />
                <mx:AnimateProperty target="{Environment}" property="y" fromValue="156" toValue="46" />
                <mx:AnimateProperty target="{ProfitAndLoss}" property="y" fromValue="156" toValue="126" />
                <mx:AnimateProperty target="{Summary}" property="y" fromValue="156" toValue="56" />
                <mx:AnimateProperty target="{Assets_Container}" property="x" fromValue="266" toValue="246" />
                <mx:AnimateProperty target="{Liabilities_Container}" property="x" fromValue="425" toValue="505" />
                <mx:Fade target="{TransactionalBackgroundImage}" alphaFrom="0" alphaTo="1" />
            </mx:Parallel>
            <mx:AnimateProperty target="{Summary}" property="x" fromValue="42" toValue="256" />
        </mx:Sequence>
    </mx:Transition>
    <mx:Transition fromState="Transactional" toState="">
        <mx:Sequence>
            <mx:AnimateProperty target="{Summary}" property="x" fromValue="256" toValue="42" />
            <mx:Parallel>
                <mx:AnimateProperty target="{Controller}" property="y" fromValue="-1" toValue="-60" />
                <mx:AnimateProperty target="{Environment}" property="y" toValue="156" fromValue="46" />
                <mx:AnimateProperty target="{ProfitAndLoss}" property="y" toValue="156" fromValue="126" />
                <mx:AnimateProperty target="{Summary}" property="y" toValue="156" fromValue="56" />
                <mx:AnimateProperty target="{Assets_Container}" property="x" fromValue="246" toValue="266" />
                <mx:AnimateProperty target="{Liabilities_Container}" property="x" fromValue="505" toValue="425" />
                <mx:Fade target="{TransactionalBackgroundImage}" alphaFrom="0" alphaTo="0" />
            </mx:Parallel>
        </mx:Sequence>
    </mx:Transition>
</transitions>

【问题讨论】:

    标签: apache-flex flex3


    【解决方案1】:

    currentState 属性会立即更改,我很确定是转换导致了问题(去过那里,做到了 ;-)。如果单击速度过快,则会有两个同时运行的效果更改同一组值,从而产生未定义的结果。此外,您的效果上的effectEnd 事件处理程序将在另一个正在运行的效果中间触发。您可以在效果实例上尝试 end() 方法以在开始下一个效果之前立即结束效果,这也会将所有属性设置为其最终值并触发 effectEnd。如果这没有帮助,您可以发布一些您的效果代码吗?

    【讨论】:

    • 您好,感谢您的回复。我在 mxml 而不是 actionscript 中定义转换。我已经发布了转换的 mxml。我现在将尝试查看是否可以在更改状态之前对每个效果调用 end() 方法。谢谢
    • 这对我来说看起来很干净,除了最后一个什么都不做的 Fade 实例:alphaFrom="0" alphaTo="0"。
    • 啊哎呀!感谢您指出了这一点!不幸的是,您建议的方法意味着过渡提前完成 - 我尝试过,但据说他们需要完成的权力。你把我放在解决方案的吐痰距离之内 - 当状态改变时,还有其他元素会简单地消失和出现 - 即没有转换只是将可见设置为假。这些属性会立即更新,因此我可以使用它们来测试是否可以进行另一次状态更改。因为没有你的帮助我不会找到它,所以我接受了你的回答。非常感谢
    • 稍加努力,您就可以拥有完整的过渡效果:在 ToggleState() 中,仅在当前没有效果运行时才更改 currentState(您可以使用 Effect 的 isPlaying 属性)。否则,请记住按钮被按下的地方,并在 effectEnd 处理程序中检查该条件以获取过渡效果。如果有“待点击”,则更改 currentState 并删除待定标志。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 2023-03-27
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多