1. 程式人生 > >flex中實現使用者登入狀態SharedObject \Timer\

flex中實現使用者登入狀態SharedObject \Timer\

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" mouseDown="init();" creationComplete="createUser();">
<mx:Script>
<![CDATA[
import mx.validators.PhoneNumberValidator;
import com.hexagonstar.util.debug.Debug;
import flash.net.SharedObject;
public static var row:int;
public var myTimer:Timer = new Timer(1000,3);
public var so:SharedObject;
[Bindable]
public var valueName:String="undefined";
[Bindable]
public var valuePwd:String="undefined";
public function createUser():void
{
so=SharedObject.getLocal("cookie");
if(so.size==0)
{
Debug.trace("你還未登入");
}
}
public function log():void
{

so.data.username="宋秋平";
so.data.pwd="123";
so.flush();
valueName=so.data.username;
}
function init():void
{

myTimer.reset();
myTimer.start();
myTimer.addEventListener("timer", timerHandler);
Debug.trace("登入狀態");
}
public function timerHandler(event:TimerEvent):void
{
Debug.trace(myTimer.currentCount);
if(myTimer.currentCount==3)
{
Debug.trace("3秒鐘你未進行認何操作,cookie銷燬,取消登入");
so.clear();
Debug.trace(so.data.username);
valueName=so.data.username;
Debug.trace(valueName);
}

}
]]>
</mx:Script>

<mx:Button label="登入" click="log()" x="139" y="95"/>
<mx:Label x="139" y="29" width="257" text="{valueName}" height="58" fontSize="12"/>



</mx:Application>