Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created March 13, 2012 14:27
Show Gist options
  • Select an option

  • Save back2dos/2029110 to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/2029110 to your computer and use it in GitHub Desktop.
tink_reactive binding example
package ;
import flash.display.DisplayObjectContainer;
import flash.events.Event;
import flash.Lib;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import haxe.PosInfos;
import haxe.Timer;
import tink.lang.Cls;
using tink.reactive.bindings.BindingTools;
/**
* ...
* @author back2dos
*/
class BindingsExample {
static function main() {
var tf = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
var ticker = new Ticker(1);
tf.text = 'foo';
Lib.current.addChild(tf);
var firstName = new Input(Lib.current, 50, 50, 'Firstname');
var lastName = new Input(Lib.current, 50, 70, 'Lastname');
tf.text.bindExpr(Std.format('Hello ${firstName.text} ${lastName.text}! ${ticker.tick} seconds elapsed since you launched this app. And here\'s a bunch of useless numbers: ${{var a = []; for (i in 0...ticker.tick%5+1) a.push(i); a.join(", ");}}'));
}
}
class Input implements Cls {
var tf:TextField;
@:bindable @:prop(tf.text, tf.text = param) var text:String;
public function new(parent:DisplayObjectContainer, x:Int, y:Int, ?text:String = '') {
this.tf = new TextField();
tf.background = tf.border = true;
tf.multiline = false;
tf.width = 150;
tf.height = 20;
tf.x = x;
tf.y = y;
tf.type = TextFieldType.INPUT;
parent.addChild(tf);
this.text = text;
tf.addEventListener(Event.CHANGE, function (_) {
bindings.fire('text');
});
}
}
class Ticker implements Cls {
@:bindable var tick:Int = 0;
public function new(tickRate:Int) {
var t = new Timer(Std.int(1000 / tickRate));
t.run = function () tick++;
}
}
@jasononeil

Copy link
Copy Markdown

I'm getting this error:

./BasicDemo.hx:47: characters 0-13 : tink.reactive.bindings.Signaller has no field fire

Is this demo still functional? I'm using tink_reactive 0.2.1

@wdanilo

wdanilo commented Jan 13, 2013

Copy link
Copy Markdown

I'm also interested in seeing working sample.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment