不依赖于Flex Framework的绑定(flight-framework)

孟福
2023-12-01
不依赖于Flex Framework的绑定(flight-framework)

项目上界面上与内存里的属性显示一直不一致,而且在做同步的时候,经常会出现不同步的情况下,而且自己定义的事件一直没有时间去彻底的整一下。今天在网上论坛里逛逛,看到一个Binding框架,试用了一下,还是蛮好用的。既然好用,那以后我们的项目就用它吧。方便又高效。
项目地址:http://code.google.com/p/flight-framework/

下面是使用代码实例:
类定义:

package  com.coolexp
package com.coolexp {

import flash.events.EventDispatcher;

import flight.events.PropertyEvent;

public class UserInfo extends EventDispatcher

{

public function UserInfo() { }

private var _age:int; public function get age():int

{

return _age;

 }

 public function set age(value:int):void

 {

var oldValue:Number = _age; _age = value; //you need to dispatch an event to indicate the binding source has changed PropertyEvent.dispatchChange(this, "age", oldValue, _age);

 }

} }

使用实例:

package{

 import com.coolexp.UserInfo;

 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.Bind;

import flight.binding.Binding;

import flight.events.PropertyEvent;

 public class TestBinding extends Sprite

{

public var txt:TextField;

 private var sourceBinding:Binding;

 public var userInfo:UserInfo;

 public function TestBinding()

 {

 txt = new TextField();

this.addChild(txt);

 userInfo = new UserInfo();

Bind.addBinding(this,"txt.text",this,"userInfo.age");

 var timer:Timer = new Timer(100);

timer.addEventListener(TimerEvent.TIMER, timer_timerHandler);

timer.start();

 }

protected function timer_timerHandler(event:TimerEvent):void

{ // TODO Auto-generated method stub userInfo.

age++;

}

 }

}

 类似资料: