Skip to content

Instantly share code, notes, and snippets.

@tpryan
Created June 28, 2011 18:31
Show Gist options
  • Save tpryan/1051820 to your computer and use it in GitHub Desktop.
Save tpryan/1051820 to your computer and use it in GitHub Desktop.
Mobile Application that closes itself 30 seconds after it loses focus.
<?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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment