0 Replies Latest reply on Nov 23, 2012 3:25 AM by Harry Kunz

    How to tell Flex to avoid bindings for constants?

    Harry Kunz Level 4

      Hi.

       

      I have a class MyClass which has a setter "type" of type string and would like to conveniently set that property like this:

       

      <something:MyClass type="{MyClass.SOMETHING}"/>

       

      Text.SOMETHING = "myvalue" is a static constant. Ofcourse a constant NEVER changes. But why on earth is flex creating a binding for it:

       

      private function _SomeClass_bindingsSetup():Array

          {

              var result:Array = [];

       

              result[0] = new mx.binding.Binding(this,

                  function():String

                  {

                      var result:* = (MyClass.SOMETHING);

                      return (result == undefined ? null : String(result));

                  },

                  null,

                  "_SomeClass_MyClass1.type"

                  );

              return result;

          }

       

      instead of just doing this: result[0] = MyClass.SOMETHING. It doesn't need the unnecessary Binding object. It seems flex is a little dumb to detect that the value in it is a constant. mxml is designed to make coding simpler by using xml constructs. But apparently i'm still forced to use the </fx:Script> construct to set the type. Plus the inconvenience to add an "id" to it to declare an unnecessary member variable just to set the type:

       

      <fx:Script>

              <![CDATA[

                     myid.type = MyClass.SOMETHING; //only workaround to avoid bindings??

                ]]>

      </fx:Script>

       

      Is there no other way to tell Flex that MyClass.SOMETHING is a constant and just replace it with the value instead of creating a useless slow binding?