3 Replies Latest reply on Jan 29, 2012 10:10 AM by Flex harUI

    Huge lag when changing currentState for the first time in simple application, Flex 4.6?


      Please try out the example code below.


      The first time I click the button it takes my PC ~ 85 ms to change states. If I click the back button afterwards, then click the button again, the lag is gone and the state change is fast. I've tried changing the creation policy, seems like it has no effect and there are deeper problems


      My questions are why is there lag the first time you click the button, and how do you fix it? I have an application that uses a state flow very similar to the code I have simplified below and this is really driving me nuts.


      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"




                                       creationPolicy="all" currentState="InitialState"

                                       width="512" height="512">



                                    import flash.utils.getTimer;

                                    protected function button1_clickHandler(event:MouseEvent):void{

                                              var time:int = getTimer();

                                              this.currentState = "ListState";

                                              trace("time to show list state:" + (getTimer() - time));



                                    protected function button2_clickHandler(event:MouseEvent):void{

                                              var time:int = getTimer();

                                              this.currentState = "InitialState";

                                              trace("time to go back:" + (getTimer() - time));





                          <s:State name="InitialState"/>

                          <s:State name="ListState"/>


                <s:Button includeIn="InitialState" click="button1_clickHandler(event)" x="221" y="221" label="Show List State"/>

                <s:Button includeIn="ListState" x="226" y="324" label="Back" click="button2_clickHandler(event)"/>

                <s:List includeIn="ListState" x="139" y="158" itemCreationPolicy="immediate">











      time to show list state:84

      time to go back:2

      time to show list state:5



      Message was edited by: Chentleman. fixed code indentation