3 Replies Latest reply on Jul 11, 2010 1:34 AM by FM_Flame

    Flex 4 How not to use data binding?

    FM_Flame Level 1

      As topic says.. I've read that for optimizating purposes we should not use data bindining. So I have this basic example of that:

      I have a main application where I define:

       

      public var appWidth:Number = 950;

       

      I have a module loaded by the mainApplication where I have this:

       

      <fx:Script>

      <![CDATA[

       

       

      import mx.core.FlexGlobals;

      ]]>

       

      </fx:Script>

       

      <s:Group width="{FlexGlobals.topLevelApplication.appWidth}" />

       

      And I get the error message:


      Data binding will not be able to detect assignments to "topLevelApplication".


      But since that is a one time set of this.. only when initializing, I do not need it to listen for changes etc, so to speak I don't need this data binding here. How do I so to speak inform the compiler of that so it doesn't give me the error message?

       

      I could define a bindable variable and assign the appWidth value to it but that beats the purpose of binding.

       

      So anyone ?

       

       

       

        • 1. Re: Flex 4 How not to use data binding?
          UbuntuPenguin Level 4

          I don't think that is a case where databinding crushes performance.  Databinding will mainly hurt you when you have lots of objects and no getters/setters on them.  Such as when bindable is declared before a class declaration.  In that case , the updating of one property causes anyone listening to ANY property on that object to have to update.

           

          You could just declare the height in a constants file.  It would be labeled public static const and you wouldn't have to worry about the binding at all , since they class wouldnt extend event dispatcher.

          1 person found this helpful
          • 2. Re: Flex 4 How not to use data binding?
            Shongrunden Adobe Employee

            If it's only set once then you could just set it using an AcrtionScript method that is called at a specific time, for example creationComplete:

             

            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           creationComplete="init()">

             

                <fx:Script>
                    <![CDATA[
                        import mx.core.FlexGlobals;

                        ...


                        private function init():void {
                            group1.width = FlexGlobals.topLevelApplication.appWidth;  
                        }

             

                    ]]>
                </fx:Script>
               
                <s:Group id="group1" />
               
            </s:Application>

            1 person found this helpful
            • 3. Re: Flex 4 How not to use data binding?
              FM_Flame Level 1

              Thanks for both comments, I greatly appreciate!

               

              So it seems there is no MXML way of doing that except the suggestion above to use a static class to share these these variables, but in addition to that I will add the the variable should be declared as public static const in order for the compiler not to throw error about the binding.

               

              If anyone knows any other way of doing that, post it here. Thanks.