flex4.5 移动设备开发,定时关闭应用程序的方法

【转】
http://www.terrenceryan.com/blog/post.cfm/delay-closing-mobile-apps-on-exit
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   creationComplete="init(event)" 
			   xmlns:s="library://ns.adobe.com/flex/spark" >
<fx:Script>
	<![CDATA[
		import mx.events.FlexEvent;
		
		public var closeTimer:Timer;
		
		protected function init(event:FlexEvent):void
		{
			NativeApplication.nativeApplication.addEventListener(
				Event.DEACTIVATE, onDeactivate);
			NativeApplication.nativeApplication.addEventListener(
				Event.ACTIVATE, onActivate);
			
		}
		
		protected function onDeactivate(event:Event):void
		{
			closeTimer = new Timer(30000,1);
			closeTimer.addEventListener(TimerEvent.TIMER_COMPLETE, 
				closeApp);
			closeTimer.start();
		}
		
		protected function closeApp(event:Event):void{
			NativeApplication.nativeApplication.exit();
		}
		
		
		protected function onActivate(event:Event):void
		{
			closeTimer = null;
			
		}
		
	]]>
</fx:Script>
</s:Application>

你可能感兴趣的:(flex4)