代码之家  ›  专栏  ›  技术社区  ›  Addsy

flex中的状态转换

  •  0
  • Addsy  · 技术社区  · 16 年前

    我有一个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>
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Simon    16 年前

    这个 currentState 属性会立即更改,我很确定是转换导致了问题(出现过,完成了;-)。如果单击速度太快,则会有两个同时运行的效果更改同一组值,从而产生未定义的结果。也, effectEnd 您的效果上的事件处理程序将在另一个正在运行的效果中间激发。你可以试试 end() 方法在效果实例上立即结束效果,然后再开始下一个,这还会将所有属性设置为其最终值和触发器 效果 . 如果这不起作用,你能发布一些效果代码吗?

    推荐文章