2 Replies Latest reply on Oct 28, 2009 10:05 AM by RickBullotta

    Issue with dynamically instantiated Spark components

    RickBullotta Level 1

      Here's an application scenario/question.  We want to dynamically create the UI at runtime based on parametric information passed in an XML file (no problem, working fine), with one gotcha we've encountered.  In order to ensure that the appropriate assets, classes, and libraries are included in and/or referenced in the SWF, we have to define/create in MXML or as ActionScript vars a dummy instance of every component we could potentially dynamically create, as below:


      import spark.components.*;


      private var dummyButton : Button = new Button();

      private var dummyLabel : Label = new Label();



      I was wondering is there was a mechanism with some type of compiler/linker directives, manifest file, or other technique to ensure that code is linked in to the SWF, even if there are no explicit references to it in the MXML code.


      What we're seeing if we do not create the dummy instances is that we're able to instantiate an instance of a Spark button, but somewhere deep in the phased instantiation logic for the display objects, the runtime is unable to find the Skin for the button.  Thus, it appears that some assets or classes are not being compiled/linked in, but other are.


      Thanks in advance for any insights.  I can provide a complete code example if needed.




        • 1. Re: Issue with dynamically instantiated Spark components
          Flex harUI Adobe Employee

          The class dependency chain is examined and used to decide which CSS selectors are added to the SWF.


          There is an MXML option called -includes which can be used to inject classes into the SWF, but I don't remember if those classes get examined and CSS selectors for them get added.  There is also an option called -keep-all-css-selectors (or something like that) that will add all CSS selectors to the SWF.  If you use that option, you can use a -config.xml file to list the other classes you want to -includes.  In recent Flex 4 builds you can see that we do that for BasicTests.mxml


          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Issue with dynamically instantiated Spark components
            RickBullotta Level 1

            @alex - Thanks!  That was exactly what I needed to get it working.


            When we extend our framework to allow runtime loading of modules containing additional (custom) UI components, it will be interesting to see what other issues we encounter in resolving the classes and skins, but this is a great start.


            Appreciate the quick response.