Reputation: 19
I would like to bind a variable which if there a changes, it will automatically update the label.
var disp:String = "00:00:00";
var lb:Label = new Label(); //Add Label to an "ContentGroup" container.
lb.text = totalTime;
addElement(lb);
disp="00:00:01"; //New timing
BindingUtils.bindProperty(totalTime, "text", disp, "text");
How do I do that?
Upvotes: 0
Views: 131
Reputation: 16718
Firstly, I want to clarify your question. You want to bind Label lb
with disp
, then later whenever disp
change, lb.text
change, is it?
Why don't use MXML (which perfectly matches with Binding mechanism) instead?
If you really want to use Actionscript, there are some points need your attention. Firstly, the "host" property has to be bindable (add [Bindable]
tag on top). Next, BindingUtils.bindProperty
should directly bind two values with each other. In this case, change to following code will work:
[Bindable] public var disp: String = "00:00:00";
private function initBinding(): void {
var lb: Label = new Label();
addElement( lb );
BindingUtils.bindProperty( lb, "text", this, "disp" );
}
By the way, I'm always avoiding using Binding if possible. Manually update properties in simple cases will save both file size and performance.
Upvotes: 1