Archive for February 18th, 2009
AS3 Binding without the Flex Framework
This example relies on the Flight Framework (included in the source) developed by my good friends Tyler, Rob, and Jacob. You can expect to see more on flight here in the future.
You can read more details about this custom binding here: http://www.xtyler.com/code/177
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.TimerEvent; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.Timer; import flight.binding.Binding; import flight.events.PropertyEvent; [SWF(backgroundColor="#ffffff")] public class BindingTest extends Sprite { private var sourceBinding:Binding; public var sourceText:TextField = new TextField(); public var targetText:TextField = new TextField(); private var isTargetTextBound:Boolean = false; //as3 binding requires a getter/setter for the property you want to bind to private var _source:Number = 0; public function get source():Number { return _source; } public function set source(value:Number):void { var oldValue:Number = _source; _source = value; //you need to dispatch an event to indicate the binding source has changed PropertyEvent.dispatchChange(this, "source", oldValue, _source); } public function BindingTest() { //set up text for visual display var textFormat:TextFormat = new TextFormat("Arial", 20, 0x000000); sourceText.defaultTextFormat = textFormat; targetText.defaultTextFormat = textFormat; addChild(sourceText); targetText.y = 40; addChild(targetText); //setup source of binding sourceBinding = new Binding(this, "source"); //bind to the first text's "text" property sourceBinding.bind(sourceText, "text"); //update with timer var timer:Timer = new Timer(100); timer.addEventListener(TimerEvent.TIMER, timer_timerHandler); timer.start(); stage.addEventListener(MouseEvent.CLICK, stage_clickHandler); } private function timer_timerHandler(event:TimerEvent):void { //increment the source source++; } private function stage_clickHandler(event:MouseEvent):void { //bind or unbind to second textField on mouse click if(isTargetTextBound) { sourceBinding.unbind(targetText, "text"); } else { sourceBinding.bind(targetText, "text"); } isTargetTextBound = !isTargetTextBound; } } } |
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- Moving to johnlindquist.com
- AsyncCommand with Robotlegs, Signals, Flight, MinimalComps
- Search Widget – Robotlegs, Signals, Flight, Minimal Comps, Yahoo Astra
- FDT Super Awesome March Deal
- haXe Tutorial
- AS3 Signals Tutorial
- Preferred Video Tutorial Resolution?
- TweenMax – Tweening a timeline (Advanced Tweening)
- Robotlegs + Flight + Union Platform
- Back in the saddle
- Eclipse Theme Designer Preview
- RobotLegs Hello World Video Tutorial
- 10 Things Every Senior Flash Developer Should Know
- Efflex – 3D Effects for Flex
- MorphController – Mighty Morphing Papervision3D
Recent Comments
- Ocatarinabelachichix on about
- Rajiv on faq
- Rajiv on 3ds max texture baking for Papervision3D
- Anupam Biswas on Maya Texture Baking
- Anupam Biswas on Maya Texture Baking
- Arindam Mojumder on requests
- Arindam Mojumder on requests
- Arindam Mojumder on Full Screen Cube
- Arindam Mojumder on faq
- Mimosa123321 on requests
Categories
Archives
Preferred Video Tutorial Resolution
- 1024x768 (53%, 85 Votes)
- 1280x1024 (15%, 24 Votes)
- 1920x1080 (15%, 24 Votes)
- 800x600 (13%, 20 Votes)
- 480x320 (4%, 6 Votes)
- 640x480 (0%, 2 Votes)
Total Voters: 160

