skip to main
|
skip to sidebar
Everything is Static.
2011年6月24日 星期五
使用actionscript binding function
今天有同事問到如何使用純as動態綁定函數於是順便研究一下相關作法.
以下範例主要是透過BindingUtils.bindProperty並傳入自己創建的Chain object來完成動態綁定函數及額外的參數更新.
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init()"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ import flash.utils.getTimer; import flash.utils.setInterval; import mx.binding.utils.BindingUtils; import mx.events.FlexEvent; protected function init():void { initBinding(lbl2, "this is lbl2"); setInterval(function():void { dispatchEvent(new Event("sayHello")); }, 1000) } protected function initBinding(obj:Object, value:String):void { var chain:Object = { name: "sayHello", value: value }; chain.getter = function(host:Object):String { return host.sayHello(chain.value); } BindingUtils.bindProperty(obj, "text", this, chain); } [Bindable(event = "sayHello")] public function sayHello(value:String):String { return "sayHello:" + value + ", time:" + getTimer(); } ]]> </fx:Script> <s:VGroup paddingTop="5" paddingLeft="5"> <s:Label id="lbl" text="{sayHello('this is lbl')}"/> <s:Label id="lbl2" text=""/> </s:VGroup> </s:Application>
沒有留言:
張貼留言
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
tag
:::
(1)
actionscript
(18)
as2
(3)
as3
(14)
AS3 Data Structures
(1)
binding
(1)
BOX2DFlashAS3
(2)
ComboBox
(1)
datagrid
(1)
dictionary
(1)
flash
(4)
flex
(7)
flex3
(4)
flex4
(3)
framework
(2)
game
(1)
include
(1)
List
(1)
ListBase
(1)
mate
(1)
menu
(1)
molehill
(1)
MXML
(1)
note
(2)
opensource
(5)
poker
(1)
PushButton Engine
(1)
QuickBox2D
(1)
scrollbar
(1)
Spark
(1)
tutorial
(3)
xml
(1)
文章
▼
2011
(4)
▼
6月
(2)
使用actionscript binding function
從MX Datagrd 升級至 Spark Datagrid 的簡易筆記心得
►
3月
(1)
►
2月
(1)
►
2010
(7)
►
2月
(3)
►
1月
(4)
►
2009
(2)
►
12月
(2)
►
2007
(7)
►
2月
(1)
►
1月
(6)
Links
TICORE'S BLOG
ATHER Shu(A.S)的Blog
Adobe User Group (Taiwan)
me
檢視我的完整簡介
沒有留言:
張貼留言