My Books

  • Follow me on Twitter

Comtaste's Projects

  • Flex Solutions: Essential Tecniques for Flex 3 Developers - The Site
  • Comtaste, Flex 3, AIR and Java consulting
  • YouThru Multimedia Web Messaging
  • MobyMobile
  • UserMatter(s) Magazine
My Photo

Subscribe my blog

  • Get this widget from Widgetbox
  • Add to Google
  • RSS FEEDS
  • Enter your Email here to subscribe :



    Powered by FeedBlitz

« Exctract and learn from the Flex 3 data visualization source code (the charting controls, the AdvancedDataGrid classes, the OLAP classes, and the automation classes) | Main | AJAX (Adobe Spry) and AIR development using Aptana IDE »

Reduce the size of a Flex 3 application avoiding unnecessary references with the getQualifiedClassName() method

There are many ways you can use to control and optimize the performance of your Flex applications acting  both on the server as well as on the client side. The first optimization you can implement is by reducing the time tha application takes to start.
Externalizing assets and searching for  linker dependencies are simple approaches that can save the end user a lot of time in  loading te Flex application.
It's common for developers that at the end of a Flex application they are inadvertently linking in some classes that they never use.
I've found that another common error is to let the compiler to include classes that the application won't use for its entire life. That's a shame !
So an important step to check before compiling and deploying a Flex app is to check that you're not including unused classes.
There is a useful method that helps you for this scenario : the getQualifiedClassName().
This class comes from the flash.utils package and it returns a String that contains the fully qualified class name of an object.
You can use it in such kind of situations where you have to compare one or more classes without linking them into the SWF file.
This is a simple scenario where we want to remove all the Button classes inside our application without  causing that class to be linked into the SWF if not used inside the file:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        initialize="removeSomeChild()">

    <mx:Script>
    <![CDATA[

    private function removeSomeChild():void
   {

        myTxt.text += "\n The number of children at the beginning " + numChildren;

        for (var i: Number = 0; i <= (this.numChildren-1); i ++)
        {          

            var childClassName:String = getQualifiedClassName(getChildAt(i));

            myTxt.text += "\n This is the full name of the class: " +  childClassName;

               switch (childClassName)
            {
                case "mx.controls::Button":
                removeChild(getChildAt(i))
            }

        }

      

        myTxt.text += "\n Children alla fine: " + numChildren;
    } 
  ]]>
    </mx:Script>

   

    <mx:TextArea id="myTxt" text="Ciao" />

    <mx:Button />

    <mx:ComboBox />
    <mx:TextInput />

</mx:Application>

The use of the getQualifiedClassName() method the following  classic syntax ensures us  to exclude the Button class  from being compiled into the SWF file :

getChildAt(i) is mx.controls.Button

Note: Removing a DisplayObject from the  DisplayList don't destroy the object neither remove it from Flash Player' s memory.The object will continue to exist even if not as a child of any other container.


Comments

Post a comment

If you have a TypeKey or TypePad account, please Sign In

Pistach.io

Speaker at

Upcoming Conferences

  • FITC200x200.jpg
  • AJAXWorld
  • CFUnited
  • SOA World Conference
  • iPhone Summit
  • 360Flex Europe

WebDeveloper's Journal Author

  • My favourite Flash Lite 3 mobile phone
  • Web Developer's & Designer's Journal by Sys Con Media
  • Web Developer's & Designer's Journal Blogger
    Web Developer's & Designer's Journal by Sys Con Media
  • FullAsGoog Aggregator
  • Macromedia WebLogs Aggregator

May 2008

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31