Created
March 13, 2012 14:27
-
-
Save back2dos/2029110 to your computer and use it in GitHub Desktop.
tink_reactive binding example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm also interested in seeing working sample.