I would like to explain to my own understanding: first of all to understand that the metadata is not a part of the syntax, but specifically for the compiler, plainly tell the compiler to do certain things, learn Java and so on should know. That bindable, its role is to tell the Flex compiler, for certain things to establish a binding relationship, the Flex compiler will be in the compilation process to the AS (Flex compiler is to compile Mxml as, and then compile to the SWF, may also directly compile the SWF, I assume there is as such a link to add a bit of event occurrence and processing code, the binding relationship is established, if we use pure AS3 code to write is also achievable, is that the missus too troublesome.
What is binding:
For example: Add [bindable] to the following public variable
[bindable]
public var name:string = "";
As a public variable, it is certainly possible to assign values and assign values to other variables. The effect of bindings is that, when name changes (assigned), other variables that are affected by name (assigned to them) may be notified to change. The "possible" here needs to be judged by the compiler, which is why metadata is given to compilers. The syntax of {} in Mxml is the binding object, such as Label={xxx.name}, and when name changes, label also changes. In this way, we simply change the name of the value, because there is a binding, the interface label also follow automatically change, cool bar.
Where can you use it?
Three places: Class, Variable, Getter/setter. Public does not have a relationship, private can only give their own use Bai. Used in class is simply to all the public attributes (including variables, getter/setter, common methods) plus [bindable], but the general method can not use [bindable] ah, so generally can see flex gave a warning, Direct disregard:). Variable is what it says, it's simple to skip off.
Used on read-only, write-only properties (Getter/setter)
Finally, the key place, because the getter and setter is very similar to the method, it will be a little different. Take a look at this example:
Copy Code code as follows:
[bindable]
private var Content:array = new Array ();
[bindable]
Public function set _content (ct:string): void
{
Content = Ct.split (SEP);
}
[bindable]
Public function Get _wholetext (): String
{
if (content.length = 0)
{
Return "";
}
Else
{
var _w:string = "";
for (var i:int=0; i<content.length; i++)
{
_w + = Content[i] + "\ r \ n";
}
return _w;
}
}
The original idea is that the content binding _wholetext, but it is not working. Why? _wholetext is too complex to be excluded by the compiler from "possible", the compiler thinks there is no binding relationship, if it is simply return content, it is OK. I have found some more authoritative explanations here. From Http://www.rubenswieringa.com/blog/binding-read-only-accessors-in-flex to find Ely Greenfield said.
Now keep in mind that there ' s no way for the compiler to ' the ' of the ' the ' the ' the ' the value of a ' Fferent if called, short of doing a extensive code flow analysis of the ' Get function ', identifying all the inputs-MIG HT is affecting the value of the ' Get function ' (i.e., member fields, statics, globals that are used in the Get function and In no methods, global functions, closures, etc) it might call, and setting up watchers on every one of those to trigger The binding a them change. That ' s prohibitively difficult, and expensive to do. So the compiler doesn ' t try.
Instead when you put [bindable] on a Get/set property, the compiler makes it bindable with a little creative rewriting tha The t allows the framework to watch the ' get function ' and dispatch a Change event the ' Get function ' is triggered. This means so automatic bindable properties don t work when the "get" function is computed to multiple values, or when Y OU change it value by setting a backing field, rather than using the SET function.
It _also_ means that if your have no set function, we can pretty much guarantee that there ' s no way automatically Get properties would be triggered. A read only propeerty are, to the compiler, completely opaque...at the moment, it has no idea where this value is coming from , and hence'll never be able to ' automatically ' trigger the binding.
The simple thing is that in order to reduce complexity and improve efficiency, the getter of complex situations is ignored. How to solve? You can manually establish a binding, that is, [bindable ("EventName")]. Change the code to this:
Copy Code code as follows:
[bindable]
private var Content:array = new Array ();
[bindable]
Public function set _content (ct:string): void
{
Content = Ct.split (SEP);
This.dispatchevent (New Event ("_contectchanged"));
}
[Bindable ("_contectchanged")]
Public function Get _wholetext (): String
{
if (content.length = 0)
{
Return "";
}
Else
{
var _w:string = "";
for (var i:int=0; i<content.length; i++)
{
_w + = Content[i] + "\ r \ n";
}
return _w;
}
}
This avoids the compiler's automatic recognition. Bind yourself with the binding, when the _content is assigned, issue the _contentchanged event, and notify all the bound getter methods to execute it again. This also shows that binding is just an event game, Flex hides many of the underlying algorithms for the user.