现在的位置: 首页 > 综合 > 正文

用actionscript代码代替[Bindable](事件监听)

2013年08月09日 ⁄ 综合 ⁄ 共 887字 ⁄ 字号 评论关闭
<?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()">
	<s:layout>
		<s:HorizontalLayout/>
	</s:layout>
	
	<fx:Script>
		<![CDATA[
			import mx.binding.utils.ChangeWatcher;
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			
			protected var _watcher:ChangeWatcher;
			
			
			protected function init():void
			{
				toggleWatch();
			}
			
			private function toggleWatch():void
			{
				if(_watcher && _watcher.isWatching()){
					_watcher.unwatch();
					toogleButton.label = "Watch";
				}else{
					_watcher = ChangeWatcher.watch(inputFiled, "text", onTextChange);
					toogleButton.label ="Stop Watching";
				}
			}
			
			
			private function onTextChange(event:Event):void
			{
				myLabel.text = inputFiled.text;
			}
			
		]]>
	</fx:Script>
	<s:Label id="myLabel"/>
	<s:TextInput id="inputFiled" text="start text"/>
	<s:Button id="toogleButton" label="Watch Text" click="toggleWatch()"/>
</s:Application>

抱歉!评论已关闭.