使用KitchenSync和CASALib延迟(delay)执行Flex的function

本文介绍如何在Flex中使用KitchenSync和CASALib库实现函数的延时和同步执行。通过具体示例展示了如何设置延时参数并按顺序执行任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要延迟(delay)执行Flex的function,或按顺序同步执行Flex的某些function,可以使用下面两个库

KitchenSync http://code.google.com/p/kitchensynclib/
CASALib http://casalib.org/

 



1.使用KitchenSync
KitchenSync并没有正式支持Flex,但没有正式支持并不代表不能使用。使用KitchenSync必须先初始化 "KitchenSync.initialize(this);" 而这个方法必须在Application的addedToStage中调用,如果在creationComplete中调用会收到一个Error: frameRateSeed must be a DisplayObject that is part of the Display List. 下面是例子代码

 

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	width="350" height="200" layout="absolute"
	addedToStage="initKitchenSync(event)">
	
	<mx:Script>
		[CDATA[
		
			import mx.controls.Alert;
			import org.as3lib.kitchensync.action.KSFunction;
			import org.as3lib.kitchensync.KitchenSync;
		
			public function initKitchenSync(evnet:Event) : void {
				KitchenSync.initialize(this);
			}
			
			public function onClickBtn() : void {
				var alertMsg : String = 
					"delay " + timeInput.value + " millisecond";
				
				var delayFunction : KSFunction = 
					new KSFunction(timeInput.value, showAlert, alertMsg);
					
				delayFunction.start();
			}
			
			public function showAlert(message : String) : void {
				Alert.show(message);
			}
			
		]]
	</mx:Script>
	
	<mx:ApplicationControlBar x="10" y="10"  
			fillAlphas="[1.0, 1.0]" fillColors="[#D3FED3, #ADC3AD]">
		<mx:Label text="Delay"/>
		<mx:NumericStepper id="timeInput" minimum="10" maximum="20000" 
			enabled="true" stepSize="200" width="89" value="1000"/>
		<mx:Label text="millisecond"/>
		<mx:Button label="Show Alert" click="onClickBtn()"/>
	</mx:ApplicationControlBar>
	
</mx:Application>

 

2.使用CASALib

CASALib不用初始化,它的Sequence相对简单些,可以在Sequence中加入多个Function

 

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	width="350" height="200" layout="absolute">
	
	<mx:Script>
		[CDATA[
			import mx.controls.Alert;
			import org.casalib.time.Sequence;
			
			public function onClickBtn() : void {
				var functionSequence : Sequence = new Sequence(false);
				functionSequence.addTask(showAlert, timeInput.value);
				//functionSequence.addTask(otherMethod, timeInput.value);
				functionSequence.start();
			}
			
			public function showAlert() : void {
				Alert.show("delay " + timeInput.value + " millisecond");
			}
			
		]]
	</mx:Script>
	
	<mx:ApplicationControlBar x="10" y="10"  
			fillAlphas="[1.0, 1.0]" fillColors="[#D3FED3, #ADC3AD]">
		<mx:Label text="Delay"/>
		<mx:NumericStepper id="timeInput" minimum="10" maximum="20000" 
			enabled="true" stepSize="200" width="89" value="1000"/>
		<mx:Label text="millisecond"/>
		<mx:Button label="Show Alert" click="onClickBtn()"/>
	</mx:ApplicationControlBar>
	
</mx:Application>

 

这两个库都还有其他很多功能,有兴趣可以深入研究

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值