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>

你可能感兴趣的:(.net,xml,Flex,Flash)