Skip navigation
Currently Being Moderated

How to tell Flex to avoid bindings for constants?

Nov 23, 2012 3:25 AM

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?

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points