2 Replies Latest reply on Nov 13, 2011 9:01 AM by srhouyu

    Application freezes because of some enterFrame event handler

    srhouyu Level 1

      Hello everyone, I use Flex 4.5 and now encounter a problem. I made some components, and used their enterFrame event  to let them update on every frame. But this doesn't always work.

       

       

      ColorChange.mxml. This component contains a rectangle which changes its color on every frame:

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" enterFrame="group1_enterFrameHandler(event)">
       <fx:Script>
        <![CDATA[
         [Bindable]protected var _color:uint = 0;
         
         protected function group1_enterFrameHandler(event:Event):void
         {
          _color += 8; // Rect's color is changed every frame
         }
        ]]>
       </fx:Script>
       <s:Rect x="0" y="0" width="100" height="100">
        <s:fill>
         <s:SolidColor color="{_color}"> 
         </s:SolidColor>
        </s:fill>
       </s:Rect>
      </s:Group>
      

       

       

       

      XChange.mxml. This component also contains a rectangle and I want it to move on every frame:

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" enterFrame="group1_enterFrameHandler(event)"> 
       <fx:Script>
        <![CDATA[
         [Bindable]protected var _x:Number = 0;
         
         protected function group1_enterFrameHandler(event:Event):void
         {
          _x += 1; // Rect's position is changed every frame
          }
        ]]>
       </fx:Script>
       <s:Rect x="{_x}" y="0" width="100" height="100">
        <s:fill>
         <s:SolidColor color="0xFF000000"> 
         </s:SolidColor>
        </s:fill>
       </s:Rect>
      </s:Group> 
      

       

       

      The two components are put into this application:

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx"
            xmlns:ns1="*"
            minWidth="955" minHeight="600">
       <ns1:ColorChange x="104" y="56">
       </ns1:ColorChange>
       <ns1:XChange x="21" y="323">
       </ns1:XChange>
      </s:Application>
      

       

       

      ColorChange works fine, but if we have XChange, the application only shows a blank page and freezes.

      I would like to know why this happens, and how I can prevent this. Thanks.