2 Replies Latest reply on Jan 19, 2009 7:46 AM by ntsiii

    Add Component Dynamically

    Murali_dharan.A
      Hai,
      I have created some components and also add some components in my application at run time (based on the conditions) using action script. Everything works fine. But the main application file size is increasing when i add more components. For example i had 3 components, if i add two components based on the conditions the main application file size is 630kb. If i remove the any one of the components the main application size is reduced. But I need to use 3 components which is based on the conditions with less file size. is it possible?

        • 1. Re: Add Component Dynamically
          Richard_Abbott Level 3
          I think you will find that in the second case the compiler does not link in any of the code relating to your component3, as it is aware that you never in fact use it. In the first case the code is present in the SWF file, even if at run-time you choose a code path that means it is never instantiated.

          As a quick test, in the second case if you replace the declaration with
          private var comp3:component3=new component3();
          (in other words declare and instantiate at the same time) then I suspect you will find the size goes back up again. Personally I prefer the style you had originally, where the instantiation is kept in a separate place, but this would help identify where the size was coming from.

          All the best,
          Richard
          • 2. Re: Add Component Dynamically
            ntsiii Level 3
            If reducing the compiled swf file size is your goal, then you have several options.

            * Use SwfLoader to load entire applicatins dynamically at run-time.
            * Use Modules for the same purpose
            * user RSLs
            * use Flex Framework caching

            See the docs or google for more info on each of these options