Working on some calculating tool for a client, i needed to bind my controller components to various properties calculated by the program. It is a single stated program, so i don’t have to worry about removing the bindings at the moment. Ease of use and performance is crucial as there is a lot of variables to bind.
It’s made in Flash CS4, but i wondered if I should use the solution in other AS3 projects as well, but I am not sure how good the solution is.
Is it something to work on?
Is there better solutions (easier to use, or better in performance)?
Examples:
BindString.as
package bindings {
/* Class */
public class BindString {
/* Private properties */
private var _string:String = new String();
private var _binds:Array = new Array();
/* Getters and setters */
public function set string(s:String):void {
_string = s;
for (var i:int = 0; i < _binds.length; i++) {
_binds*();
}
}
public function get string():String {
return _string;
}
/* Methods */
public function bindTo(f:Function):void {
_binds.push(f);
}
}
}
Use:
var myString:BindString = new BindString();
myString.bindTo(onMyStringChange);
function onMyStringChange():void {
trace("string changed to", myString.string);
}
myString.string = "Yo";
Same principle goes for int, Number, Boolean, etc.