3 Replies Latest reply on Aug 23, 2010 6:48 AM by Vackar

    Flex Air Performance Issue

    Yue_Hong Level 1

      Hi,

       

      I am trying to build a Flex Air application which consist a few flash content (images transition & marquee text) loaded with swfloader. Sometimes it will playback some videos when it trigger some command. However, during my early stage of development, I encounter the performance trouble. Currently, I only have 2 flash swf files loaded into the scene. One is the image transition, and the other one is marquee text. My project scene size is 1280 x 720. I have set all the component to resize it when display in fullscreen mode to have the correct size and position for every component. However, after I try to run the display for a few minutes on my corei7 PC, everything starts to slow down. Especially during the flash image transition (just a basic fade in and out between 2 image), and it use out all my corei7 processor core usage.

       

      Basically just 2 simple flash component and begin to slow down after a few moment.

      Why is this happen?!!! How can I solve it? Thanks.

        • 1. Re: Flex Air Performance Issue
          Vackar Level 2

          Could you post your code, it'll make it easier to spot the problem.


          • 2. Re: Flex Air Performance Issue
            Yue_Hong Level 1

            Here is my code:

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:WindowedApplication 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="1280" height="720" backgroundColor="#0000FF" showStatusBar="false"
                                        applicationComplete="init(event)">
            
                 <fx:Script>
                      <![CDATA[
                           
                           import mx.events.FlexEvent;
                                    import org.osmf.events.TimeEvent;
                           
                           protected function adjustScreen():void
                           {
                                var sWidth:Number = this.width;
                                var sHeight:Number = this.height;
                                
                                
                                // stage height is larger / taller than 16:9
                                if (sHeight/sWidth > 0.5625){
                                     backImage.width = sWidth;
                                     backImage.height = backImage.width * 0.5625;
                                }
                                // stage width is larger / taller than 16:9
                                if (sHeight/sWidth < 0.5625){
                                     backImage.height = sHeight;
                                     backImage.width = backImage.height / 0.5625;
                                }
                                // stage size is 16:9
                                if (sHeight/sWidth == 0.5625){
                                     backImage.height = sHeight;
                                     backImage.width = sWidth;
                                }
                                
                                //MainContent
                                var scaleRatio:Number = backImage.height/720;
                                mainContent.height = 505 * scaleRatio;
                                mainContent.width = 943 * scaleRatio;
                                
                                marqueeText.height = 44 * scaleRatio;
                                marqueeText.width = 943 * scaleRatio;
                                
                                
                                // stage height is larger / taller than 16:9
                                if (sHeight/sWidth > 0.5625){
                                     mainContent.x = 29 * scaleRatio
                                     mainContent.y = 95 * scaleRatio + (this.height - (this.width * 0.5625))/2;
                                     
                                     marqueeText.x = 29 * scaleRatio
                                     marqueeText.y = 646 * scaleRatio + (this.height - (this.width * 0.5625))/2;
                                }
                                // stage width is larger / taller than 16:9
                                if (sHeight/sWidth < 0.5625){
                                     mainContent.x = 29 * scaleRatio + (this.width - (this.height / 0.5625))/2;
                                     mainContent.y = 95 * scaleRatio
                                          
                                     marqueeText.x = 29 * scaleRatio + (this.width - (this.height / 0.5625))/2;
                                     marqueeText.y = 646 * scaleRatio
                                }
                                // stage size is 16:9
                                if (sHeight/sWidth == 0.5625){
                                     mainContent.x = 29 * scaleRatio;
                                     mainContent.y = 95 * scaleRatio;
                                     
                                     marqueeText.x = 29 * scaleRatio;
                                     marqueeText.y = 646 * scaleRatio;
                                }
                                
                           }
            
                           protected function init(event:FlexEvent):void
                           {
                                stage.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
                                adjustScreen();
                           }
            
                           public function handleKeyUp(event:KeyboardEvent) :void
                           {
                                if (event.charCode == 13){ // Enter Pressed
                                     stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
                                }
                                
                                if (event.charCode == 27){ // ESC Pressed
                                     stage.displayState = StageDisplayState.NORMAL;
                                }
                                
                                if (this.currentState == "State1"){
                                     if (String.fromCharCode(event.charCode) == "1"){
                                          this.currentState = "video";
                                          videoContent.source = "video/Growth (ENG).mp4";
                                     }
                                     
                                     if (String.fromCharCode(event.charCode) == "2"){
                                          this.currentState = "video";
                                          videoContent.source = "video/Stability (ENG).mp4";
                                     }
                                     
                                     if (String.fromCharCode(event.charCode) == "3"){
                                          this.currentState = "video";
                                          videoContent.source = "video/Strength (ENG).mp4";
                                     }
                                     
                                }
                                adjustScreen();
                           }
            
                           protected function videoContent_completeHandler(event:TimeEvent):void
                           {
                                this.currentState = "";
                                adjustScreen();
                           }
            
            
                      ]]>
                 </fx:Script>
                 <s:states>
                      <s:State name="State1"/>
                      <s:State name="video"/>
                 </s:states>
                 <s:transitions>
                      <s:Transition>
                           <s:Fade targets="{[mainContent, videoContent]}"/>
                      </s:Transition>
                 </s:transitions>
                 <fx:Declarations>
                      <!-- Place non-visual elements (e.g., services, value objects) here -->
                 </fx:Declarations>
                 <mx:Image id="backImage" source="assets/background.jpg" smoothBitmapContent="true" maintainAspectRatio="true" horizontalCenter="0" verticalCenter="0"/>
                 <mx:SWFLoader id="mainContent" source="assets/mainContent.swf" smoothBitmapContent="false" maintainAspectRatio="true" x="29" y="95" includeIn="State1"/>
                 
                 <s:VideoDisplay id="videoContent" complete="videoContent_completeHandler(event)" includeIn="video" x="{mainContent.x}" y="{mainContent.y}" width="{mainContent.width}" height="{mainContent.height}"/>
                 <mx:SWFLoader id="marqueeText" source="assets/marquee.swf" smoothBitmapContent="true" maintainAspectRatio="true" x="29" y="646" scrollRect="{new Rectangle(0, 0, marqueeText.width, marqueeText.height)}"/>
                 
            </s:WindowedApplication>
            
            

             

            The mainContent.swf is the swf flash which contains 2 image rotations with fade in as the transition effect.

             

            The marquee.swf is the swf flash with text that move from right to left continuously.

            • 3. Re: Flex Air Performance Issue
              Vackar Level 2

              Do you have the source for the two swfs?

               

              If so, you could try loading them as modules into your app. I can't guarantee it but I have a feeling that it will speed it up.

               

              And from the sound of it, it shouldn't be that hard to re-write them from scratch, just two simple components that you can then add directly to you app.

               

              Vackar