In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Client Attributeの応答時間テスト

ClientAttributeUpdate
@author Copyright (C) naoto koshikawa, All Rights Reserved.
Get Adobe Flash player
by naoto5959 07 Sep 2009
/**
 * Copyright naoto5959 ( http://wonderfl.net/user/naoto5959 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tahy
 */

package  
{
	import com.bit101.components.PushButton;
	import com.bit101.components.Text;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import net.user1.reactor.Attribute;
	import net.user1.reactor.Reactor;
	import net.user1.reactor.ReactorEvent;
	import net.user1.reactor.Room;
	import net.user1.reactor.RoomEvent;
	
	/**
	 * ClientAttributeUpdate
	 * @author Copyright (C) naoto koshikawa, All Rights Reserved.
	 */
	public class ClientAttributeUpdate extends Sprite
	{
		//----------------------------------------------------------------------
		//  properties
		//----------------------------------------------------------------------
		//------------------------------
		//  private propeties
		//------------------------------
		/**
		 * Reactor
		 */
		private var _reactor:Reactor;
		
		/**
		 * Room
		 */
		private var _room:Room;
		
		/**
		 * push button
		 */
		private var _pushButton:PushButton;
		
		/**
		 * result text
		 */
		private var _resultText:Text;
		
		/**
		 * Date
		 */
		private var _date:Date;
		
		//----------------------------------------------------------------------
		//  methods
		//----------------------------------------------------------------------
		//------------------------------
		//  public methods
		//------------------------------
		/**
		 * constructor
		 */
		public function ClientAttributeUpdate() 
		{	
			_pushButton = new PushButton(
				this, (465 - 100) / 2 , 465 / 2, "update!!");
			_pushButton.setSize(100, 100);
			
			_resultText = new Text(
				this, (465 - 100) / 2 , 465 / 2 - 100, "wait");
			_resultText.setSize(100, 100);
			
			_reactor = new Reactor();
			_reactor.addEventListener(ReactorEvent.READY, 
				_reactor_readyHandler);
			_reactor.connect("tryunion.com", 9100);
		}
		
		//----------------------------------------------------------------------
		//  event handler
		//----------------------------------------------------------------------
		/**
		 * @param event
		 */
		private function _reactor_readyHandler(event:ReactorEvent):void
		{
			_room = _reactor.getRoomManager().createRoom(
				"com.asmple.union.alpha4.test");
			_room.addEventListener(RoomEvent.JOIN, _room_joinHandler);
			_room.addEventListener(RoomEvent.UPDATE_CLIENT_ATTRIBUTE,
				_room_udpateClientAttributeHandler);
			_room.join();
		}
		
		/**
		 * @param event
		 */
		private function _room_joinHandler(event:RoomEvent):void
		{
			_pushButton.addEventListener(MouseEvent.CLICK,
				_pushButton_clickHandler);
			_resultText.text = "ready";
		}
		
		/**
		 * @param event
		 */
		private function _pushButton_clickHandler(event:MouseEvent):void
		{
			_reactor.getClientManager().self().setAttribute("time",
				new Date().getTime().toString());
		}
		
		/**
		 * @param event
		 */
		private function _room_udpateClientAttributeHandler(event:RoomEvent):void
		{
			var attribute:Attribute = event.getChangedAttr();
			if (attribute.name != "time") return;

			var time:Number = Number(attribute.value);
			_resultText.text = String(new Date().getTime() - time);
		}
	}	
}