diff --git a/ChatRoom/.actionScriptProperties b/ChatRoom/.actionScriptProperties index 2f6ba27..51b9c06 100644 --- a/ChatRoom/.actionScriptProperties +++ b/ChatRoom/.actionScriptProperties @@ -1,60 +1,54 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ChatRoom/.settings/org.eclipse.core.resources.prefs b/ChatRoom/.settings/org.eclipse.core.resources.prefs index c7d0b73..c425f16 100644 --- a/ChatRoom/.settings/org.eclipse.core.resources.prefs +++ b/ChatRoom/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,3 @@ -#Tue Jul 02 16:46:57 IST 2013 -eclipse.preferences.version=1 -encoding/=utf-8 +#Wed Jul 24 10:06:45 CST 2013 +eclipse.preferences.version=1 +encoding/=utf-8 diff --git a/ChatRoom/src/AppWarpChatRoomDemo-app.xml b/ChatRoom/src/AppWarpChatRoomDemo-app.xml index 5c1e463..885d049 100644 --- a/ChatRoom/src/AppWarpChatRoomDemo-app.xml +++ b/ChatRoom/src/AppWarpChatRoomDemo-app.xml @@ -1,247 +1,247 @@ - - - - - - - AppWarpChatRoomDemo - - - AppWarpChatRoomDemo - - - AppWarpChatRoomDemo - - - 0.0.0 - - - - - - - - - - - - - - - - - - [This value will be overwritten by Flash Builder in the output app.xml] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - false - false - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + AppWarpChatRoomDemo + + + AppWarpChatRoomDemo + + + AppWarpChatRoomDemo + + + 0.0.0 + + + + + + + + + + + + + + + + + + [This value will be overwritten by Flash Builder in the output app.xml] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ChatRoom/src/AppWarpChatRoomDemo.as b/ChatRoom/src/AppWarpChatRoomDemo.as index 9e0efd1..066b02d 100644 --- a/ChatRoom/src/AppWarpChatRoomDemo.as +++ b/ChatRoom/src/AppWarpChatRoomDemo.as @@ -1,373 +1,377 @@ -import com.shephertz.appwarp.WarpClient; -import com.shephertz.appwarp.listener.ChatRequestListener; -import com.shephertz.appwarp.listener.ConnectionRequestListener; -import com.shephertz.appwarp.listener.NotificationListener; -import com.shephertz.appwarp.listener.RoomRequestListener; -import com.shephertz.appwarp.messages.Chat; -import com.shephertz.appwarp.messages.LiveRoom; -import com.shephertz.appwarp.messages.Lobby; -import com.shephertz.appwarp.messages.Room; -import com.shephertz.appwarp.types.ResultCode; -import com.shephertz.appwarp.messages.Move; - - -import flash.text.TextField; -import flash.utils.ByteArray; - -var outputTextField:TextField = new TextField(); -var userinputTextField:TextField = new TextField(); -var connectbtn:TextField = new TextField(); -var disconnectbtn:TextField = new TextField(); -var chatBtn:TextField = new TextField(); - -// AppWarp String Constants -var roomID:String = "1799555827"; -var apiKey:String = "b29f4030aba3b2bc7002c4eae6815a4130c862c386e43ae2a0a092b27de1c5af" -var secretKey:String = "bf45f27e826039754f8dda659166d59ffb7b9dce830ac51d6e6b576ae4b26f7e"; - -// Watermark Text -var NAME_PROMPT:String = "Enter name and click connect.."; -var CHAT_PROMPT:String = "Type message.."; - -// COLORS -var GREY:uint = 0x999999; -var BLACK:uint = 0x000000; -var WHITE:uint = 0xFFFFFF; -var RED:uint = 0xDF0101; - -// AppWarp Reference -var appwarp:WarpClient; - -/* -Handle connection events. If successfully connected, send join room request. -*/ -class connectionListener implements ConnectionRequestListener -{ - public function onConnectDone(res:int):void - { - if(res == ResultCode.success) - { - appwarp.joinRoom(roomID); - } - else{ - outputTextField.text += "\nConnection Failed!"; - connectbtn.backgroundColor = BLACK; - chatBtn.backgroundColor = GREY; - disconnectbtn.backgroundColor = GREY; - } - } - - public function onDisConnectDone(res:int):void - { - outputTextField.text += "\nDisconnected!"; - userinputTextField.text = NAME_PROMPT; - userinputTextField.textColor = GREY; - connectbtn.backgroundColor = BLACK; - chatBtn.backgroundColor = GREY; - disconnectbtn.backgroundColor = GREY; - } -} - -/* -Handle responses for room requests. -First Join, then Subscribe the room. Alert the user in case -any operation fails. -*/ -class roomListener implements RoomRequestListener -{ - public function onSubscribeRoomDone(event:Room):void - { - if(event.result == ResultCode.success){ - outputTextField.text += "\nReady To Chat!"; - userinputTextField.text = CHAT_PROMPT; - userinputTextField.textColor = GREY; - chatBtn.backgroundColor = BLACK; - disconnectbtn.backgroundColor = BLACK; - } - else{ - outputTextField.text += "\nSubscribe Room Failed!"; - } - } - public function onUnsubscribeRoomDone(event:Room):void - { - } - - public function onJoinRoomDone(event:Room):void - { - if(event.result == ResultCode.success){ - appwarp.subscribeRoom(roomID); - } - else{ - outputTextField.text += "Room Join Failed!" - } - } - - public function onLeaveRoomDone(event:Room):void - { - } - - public function onGetLiveRoomInfoDone(event:LiveRoom):void - { - } - - public function onSetCustomRoomDataDone(event:LiveRoom):void - { - } - - public function onUpdatePropertiesDone(event:LiveRoom):void - { - } - - public function onLockPropertiesDone(result:int):void - { - - } - - public function onUnlockPropertiesDone(result:int):void - { - - } -} - -/* -Handle response for chat request. Alert user in case sending failed. -*/ -class chatlistner implements ChatRequestListener -{ - public function onSendChatDone(res:int):void - { - if(res != ResultCode.success){ - outputTextField.text += "\nonSendChatDone : "+res; - } - else{ - chatBtn.backgroundColor = BLACK; - userinputTextField.text = CHAT_PROMPT; - userinputTextField.textColor = GREY; - } - } - - public function onSendPrivateChatDone(res:int):void - { - - } -} - -/* -Handle notification events from AppWarp -users joining/leaving and chat message events. -*/ -class notifylistener implements NotificationListener -{ - public function onRoomCreated(event:Room):void - { - } - public function onRoomDestroyed(event:Room):void - { - } - public function onUserLeftRoom(event:Room, user:String):void - { - outputTextField.text += "\n"+user+" has left"; - } - public function onUserJoinedRoom(event:Room, user:String):void - { - outputTextField.text += "\n"+user+" has joined"; - } - public function onUserLeftLobby(event:Lobby, user:String):void - { - } - public function onUserJoinedLobby(event:Lobby, user:String):void - { - } - public function onChatReceived(event:Chat):void - { - outputTextField.text += "\n"+ event.sender+ ": " +event.chat; - } - public function onPrivateChatReceived(sender:String, message:String):void - { - - } - public function onUpdatePeersReceived(update:ByteArray):void - { - } - public function onUserChangeRoomProperties(room:Room, user:String,properties:Object, lockTable:Object):void - { - } - - public function onMoveCompleted(moveEvent:Move):void - { - - } -} - -package -{ - import com.shephertz.appwarp.WarpClient; - import com.shephertz.appwarp.listener.ConnectionRequestListener; - import com.shephertz.appwarp.types.ConnectionState; - - import flash.display.Sprite; - import flash.events.FocusEvent; - import flash.events.MouseEvent; - import flash.text.TextField; - import flash.text.TextFormat; - import flash.text.TextFormatAlign; - - public class AppWarpChatRoomDemo extends Sprite - { - - public function AppWarpChatRoomDemo() - { - PrepareChatUI(); - - // Initialize and register listeners. - WarpClient.initialize(apiKey, secretKey); - appwarp = WarpClient.getInstance(); - appwarp.setConnectionRequestListener(new connectionListener()); - appwarp.setRoomRequestListener(new roomListener()); - appwarp.setChatRequestListener(new chatlistner()); - appwarp.setNotificationListener(new notifylistener()); - } - - - private function sendchat_click(e:MouseEvent):void - { - if(appwarp.getConnectionState() == ConnectionState.connected){ - if(userinputTextField.text != CHAT_PROMPT){ - // Send the chat message - appwarp.sendChat(userinputTextField.text); - - chatBtn.backgroundColor = GREY; - } - } - } - - private function connect_click(e:MouseEvent):void - { - if(appwarp.getConnectionState() == ConnectionState.disconnected){ - if(userinputTextField.text != NAME_PROMPT){ - // Connect to AppWarp - appwarp.connect(userinputTextField.text); - - outputTextField.text += "\nConnecting..."; - connectbtn.backgroundColor = GREY; - } - } - } - - private function disconnect_click(e:MouseEvent):void - { - if(appwarp.getConnectionState() == ConnectionState.connected){ - // Disconnect from AppWarp - appwarp.disconnect(); - } - } - - private function PrepareChatUI():void - { - var headerFormat:TextFormat = new TextFormat(); - headerFormat.size = 20; - headerFormat.bold = true; - headerFormat.align = TextFormatAlign.LEFT; - - var headerLine1:TextField = new TextField(); - headerLine1.defaultTextFormat = headerFormat; - headerLine1.text = "AppWarp AS3 FLASH"; - addChild(headerLine1); - headerLine1.wordWrap = true; - headerLine1.width = 250; - headerLine1.height = 30; - headerLine1.textColor = RED; - headerLine1.x = 0; - headerLine1.y = 0; - - - var headerLine2:TextField = new TextField(); - headerLine2.defaultTextFormat = headerFormat; - headerLine2.text = "Chat Demo"; - addChild(headerLine2); - headerLine2.wordWrap = true; - headerLine2.width = 200; - headerLine2.height = 25; - headerLine2.textColor = BLACK; - headerLine2.x = 0; - headerLine2.y = 30; - - - outputTextField.width = 600; - outputTextField.height = 900; - outputTextField.y = 55; - addChild(outputTextField); - - userinputTextField.width = 265; - userinputTextField.height = 30; - userinputTextField.x = 220; - userinputTextField.text = NAME_PROMPT; - userinputTextField.textColor = GREY; - userinputTextField.border = true; - userinputTextField.type = "input"; - userinputTextField.addEventListener(FocusEvent.FOCUS_IN, focusHandler); - userinputTextField.addEventListener(FocusEvent.FOCUS_OUT, focusHandler); - addChild(userinputTextField); - - connectbtn.y = userinputTextField.height + userinputTextField.y + 5; - connectbtn.x = 220; - connectbtn.selectable = false; - connectbtn.width = 60; - connectbtn.height = 25; - connectbtn.background = true; - connectbtn.backgroundColor = BLACK; - connectbtn.textColor = WHITE; - connectbtn.text = "Connect"; - connectbtn.addEventListener(MouseEvent.CLICK,connect_click); - addChild(connectbtn); - - disconnectbtn.y = userinputTextField.height + userinputTextField.y + 5; - disconnectbtn.x = 400; - disconnectbtn.selectable = false; - disconnectbtn.width = 65; - disconnectbtn.height = 25; - disconnectbtn.background = true; - disconnectbtn.backgroundColor = GREY; - disconnectbtn.textColor = WHITE; - disconnectbtn.text = "Disconnect"; - disconnectbtn.addEventListener(MouseEvent.CLICK,disconnect_click); - addChild(disconnectbtn); - - chatBtn.y = userinputTextField.height + userinputTextField.y + 5; - chatBtn.x = 300; - chatBtn.selectable = false; - chatBtn.width = 60; - chatBtn.height = 25; - chatBtn.background = true; - chatBtn.backgroundColor = GREY; - chatBtn.textColor = WHITE; - chatBtn.text = "Send Chat"; - chatBtn.addEventListener(MouseEvent.CLICK,sendchat_click); - addChild(chatBtn); - } - - // Watermark text handling - private function focusHandler(event:FocusEvent):void - { - switch (event.type) { - case FocusEvent.FOCUS_IN: - if (userinputTextField.text == NAME_PROMPT || userinputTextField.text == CHAT_PROMPT) { - userinputTextField.text = ""; - userinputTextField.textColor = BLACK; - } - break; - case FocusEvent.FOCUS_OUT: - if (userinputTextField.text == "") { - if(appwarp.getConnectionState() == ConnectionState.disconnected){ - userinputTextField.text = NAME_PROMPT; - } - else{ - userinputTextField.text = CHAT_PROMPT; - } - userinputTextField.textColor = GREY; - } - break; - } - } - } +/* +Handle connection events. If successfully connected, send join room request. +*/ +//class connectionListener implements ConnectionRequestListener +//{ +// public function onConnectDone(res:int):void +// { +// if(res == ResultCode.success) +// { +// appwarp.joinRoom(roomID); +// } +// else{ +// outputTextField.text += "\nConnection Failed!"; +// connectbtn.backgroundColor = BLACK; +// chatBtn.backgroundColor = GREY; +// disconnectbtn.backgroundColor = GREY; +// } +// } +// +// public function onDisConnectDone(res:int):void +// { +// outputTextField.text += "\nDisconnected!"; +// userinputTextField.text = NAME_PROMPT; +// userinputTextField.textColor = GREY; +// connectbtn.backgroundColor = BLACK; +// chatBtn.backgroundColor = GREY; +// disconnectbtn.backgroundColor = GREY; +// } +//} + +/* +Handle responses for room requests. +First Join, then Subscribe the room. Alert the user in case +any operation fails. +*/ +//class roomListener implements RoomRequestListener +//{ +// public function onSubscribeRoomDone(event:Room):void +// { +// if(event.result == ResultCode.success){ +// outputTextField.text += "\nReady To Chat!"; +// userinputTextField.text = CHAT_PROMPT; +// userinputTextField.textColor = GREY; +// chatBtn.backgroundColor = BLACK; +// disconnectbtn.backgroundColor = BLACK; +// } +// else{ +// outputTextField.text += "\nSubscribe Room Failed!"; +// } +// } +// public function onUnsubscribeRoomDone(event:Room):void +// { +// } +// +// public function onJoinRoomDone(event:Room):void +// { +// if(event.result == ResultCode.success){ +// appwarp.subscribeRoom(roomID); +// } +// else{ +// outputTextField.text += "Room Join Failed!" +// } +// } +// +// public function onLeaveRoomDone(event:Room):void +// { +// } +// +// public function onGetLiveRoomInfoDone(event:LiveRoom):void +// { +// } +// +// public function onSetCustomRoomDataDone(event:LiveRoom):void +// { +// } +// +// public function onUpdatePropertiesDone(event:LiveRoom):void +// { +// } +// +// public function onLockPropertiesDone(result:int):void +// { +// +// } +// +// public function onUnlockPropertiesDone(result:int):void +// { +// +// } +//} + +/* +Handle response for chat request. Alert user in case sending failed. +*/ +//class chatlistner implements ChatRequestListener +//{ +// public function onSendChatDone(res:int):void +// { +// if(res != ResultCode.success){ +// outputTextField.text += "\nonSendChatDone : "+res; +// } +// else{ +// chatBtn.backgroundColor = BLACK; +// userinputTextField.text = CHAT_PROMPT; +// userinputTextField.textColor = GREY; +// } +// } +// +// public function onSendPrivateChatDone(res:int):void +// { +// +// } +//} + +/* +Handle notification events from AppWarp +users joining/leaving and chat message events. +*/ +//class notifylistener implements NotificationListener +//{ +// public function onRoomCreated(event:Room):void +// { +// } +// public function onRoomDestroyed(event:Room):void +// { +// } +// public function onUserLeftRoom(event:Room, user:String):void +// { +// outputTextField.text += "\n"+user+" has left"; +// } +// public function onUserJoinedRoom(event:Room, user:String):void +// { +// outputTextField.text += "\n"+user+" has joined"; +// } +// public function onUserLeftLobby(event:Lobby, user:String):void +// { +// } +// public function onUserJoinedLobby(event:Lobby, user:String):void +// { +// } +// public function onChatReceived(event:Chat):void +// { +// outputTextField.text += "\n"+ event.sender+ ": " +event.chat; +// } +// public function onPrivateChatReceived(sender:String, message:String):void +// { +// +// } +// public function onUpdatePeersReceived(update:ByteArray):void +// { +// } +// public function onUserChangeRoomProperties(room:Room, user:String,properties:Object, lockTable:Object):void +// { +// } +// +// public function onMoveCompleted(moveEvent:Move):void +// { +// +// } +//} + +package +{ + import com.shephertz.appwarp.WarpClient; + import com.shephertz.appwarp.listener.ConnectionRequestListener; + import com.shephertz.appwarp.types.ConnectionState; + + import flash.display.Sprite; + import flash.events.FocusEvent; + import flash.events.MouseEvent; + import flash.text.TextField; + import flash.text.TextFormat; + import flash.text.TextFormatAlign; + + import com.shephertz.appwarp.WarpClient; + import com.shephertz.appwarp.listener.ChatRequestListener; + import com.shephertz.appwarp.listener.ConnectionRequestListener; + import com.shephertz.appwarp.listener.NotificationListener; + import com.shephertz.appwarp.listener.RoomRequestListener; + import com.shephertz.appwarp.messages.Chat; + import com.shephertz.appwarp.messages.LiveRoom; + import com.shephertz.appwarp.messages.Lobby; + import com.shephertz.appwarp.messages.Room; + import com.shephertz.appwarp.types.ResultCode; + import com.shephertz.appwarp.messages.Move; + + + import flash.text.TextField; + import flash.utils.ByteArray; + + + public class AppWarpChatRoomDemo extends Sprite + { + public var outputTextField:TextField = new TextField(); + public var userinputTextField:TextField = new TextField(); + public var connectbtn:TextField = new TextField(); + public var disconnectbtn:TextField = new TextField(); + public var chatBtn:TextField = new TextField(); + + // AppWarp String Constants + public var roomID:String = "1799555827"; + public var apiKey:String = "b29f4030aba3b2bc7002c4eae6815a4130c862c386e43ae2a0a092b27de1c5af" + public var secretKey:String = "bf45f27e826039754f8dda659166d59ffb7b9dce830ac51d6e6b576ae4b26f7e"; + + // Watermark Text + public var NAME_PROMPT:String = "Enter name and click connect.."; + public var CHAT_PROMPT:String = "Type message.."; + + // COLORS + public var GREY:uint = 0x999999; + public var BLACK:uint = 0x000000; + public var WHITE:uint = 0xFFFFFF; + public var RED:uint = 0xDF0101; + + // AppWarp Reference + public var appwarp:WarpClient; + + private var listener:AppWarpListener; + + public function AppWarpChatRoomDemo() + { + PrepareChatUI(); + + // Initialize and register listeners. + WarpClient.initialize(apiKey, secretKey); + listener = new AppWarpListener(this); + appwarp = WarpClient.getInstance(); + appwarp.setConnectionRequestListener(listener); + appwarp.setRoomRequestListener(listener); + appwarp.setChatRequestListener(listener); + appwarp.setNotificationListener(listener); + } + + + private function sendchat_click(e:MouseEvent):void + { + if(appwarp.getConnectionState() == ConnectionState.connected){ + if(userinputTextField.text != CHAT_PROMPT){ + // Send the chat message + appwarp.sendChat(userinputTextField.text); + + chatBtn.backgroundColor = GREY; + } + } + } + + private function connect_click(e:MouseEvent):void + { + if(appwarp.getConnectionState() == ConnectionState.disconnected){ + if(userinputTextField.text != NAME_PROMPT){ + // Connect to AppWarp + appwarp.connect(userinputTextField.text); + +// outputTextField.text += "\nConnecting..."; + outputTextField.appendText("\nConnecting..."); + connectbtn.backgroundColor = GREY; + } + } + } + + private function disconnect_click(e:MouseEvent):void + { + if(appwarp.getConnectionState() == ConnectionState.connected){ + // Disconnect from AppWarp + appwarp.disconnect(); + } + } + + private function PrepareChatUI():void + { + var headerFormat:TextFormat = new TextFormat(); + headerFormat.size = 20; + headerFormat.bold = true; + headerFormat.align = TextFormatAlign.LEFT; + + var headerLine1:TextField = new TextField(); + headerLine1.defaultTextFormat = headerFormat; + headerLine1.text = "AppWarp AS3 FLASH"; + addChild(headerLine1); + headerLine1.wordWrap = true; + headerLine1.width = 250; + headerLine1.height = 30; + headerLine1.textColor = RED; + headerLine1.x = 0; + headerLine1.y = 0; + + + var headerLine2:TextField = new TextField(); + headerLine2.defaultTextFormat = headerFormat; + headerLine2.text = "Chat Demo"; + addChild(headerLine2); + headerLine2.wordWrap = true; + headerLine2.width = 200; + headerLine2.height = 25; + headerLine2.textColor = BLACK; + headerLine2.x = 0; + headerLine2.y = 30; + + + outputTextField.width = 600; + outputTextField.height = 900; + outputTextField.y = 55; + addChild(outputTextField); + + userinputTextField.width = 265; + userinputTextField.height = 30; + userinputTextField.x = 220; + userinputTextField.text = NAME_PROMPT; + userinputTextField.textColor = GREY; + userinputTextField.border = true; + userinputTextField.type = "input"; + userinputTextField.addEventListener(FocusEvent.FOCUS_IN, focusHandler); + userinputTextField.addEventListener(FocusEvent.FOCUS_OUT, focusHandler); + addChild(userinputTextField); + + connectbtn.y = userinputTextField.height + userinputTextField.y + 5; + connectbtn.x = 220; + connectbtn.selectable = false; + connectbtn.width = 60; + connectbtn.height = 25; + connectbtn.background = true; + connectbtn.backgroundColor = BLACK; + connectbtn.textColor = WHITE; + connectbtn.text = "Connect"; + connectbtn.addEventListener(MouseEvent.CLICK,connect_click); + addChild(connectbtn); + + disconnectbtn.y = userinputTextField.height + userinputTextField.y + 5; + disconnectbtn.x = 400; + disconnectbtn.selectable = false; + disconnectbtn.width = 65; + disconnectbtn.height = 25; + disconnectbtn.background = true; + disconnectbtn.backgroundColor = GREY; + disconnectbtn.textColor = WHITE; + disconnectbtn.text = "Disconnect"; + disconnectbtn.addEventListener(MouseEvent.CLICK,disconnect_click); + addChild(disconnectbtn); + + chatBtn.y = userinputTextField.height + userinputTextField.y + 5; + chatBtn.x = 300; + chatBtn.selectable = false; + chatBtn.width = 60; + chatBtn.height = 25; + chatBtn.background = true; + chatBtn.backgroundColor = GREY; + chatBtn.textColor = WHITE; + chatBtn.text = "Send Chat"; + chatBtn.addEventListener(MouseEvent.CLICK,sendchat_click); + addChild(chatBtn); + } + + // Watermark text handling + private function focusHandler(event:FocusEvent):void + { + switch (event.type) { + case FocusEvent.FOCUS_IN: + if (userinputTextField.text == NAME_PROMPT || userinputTextField.text == CHAT_PROMPT) { + userinputTextField.text = ""; + userinputTextField.textColor = BLACK; + } + break; + case FocusEvent.FOCUS_OUT: + if (userinputTextField.text == "") { + if(appwarp.getConnectionState() == ConnectionState.disconnected){ + userinputTextField.text = NAME_PROMPT; + } + else{ + userinputTextField.text = CHAT_PROMPT; + } + userinputTextField.textColor = GREY; + } + break; + } + } + } } \ No newline at end of file diff --git a/ChatRoom/src/AppWarpListener.as b/ChatRoom/src/AppWarpListener.as new file mode 100644 index 0000000..bfb7f76 --- /dev/null +++ b/ChatRoom/src/AppWarpListener.as @@ -0,0 +1,164 @@ +package +{ + import com.shephertz.appwarp.WarpClient; + import com.shephertz.appwarp.listener.ChatRequestListener; + import com.shephertz.appwarp.listener.ConnectionRequestListener; + import com.shephertz.appwarp.listener.NotificationListener; + import com.shephertz.appwarp.listener.RoomRequestListener; + import com.shephertz.appwarp.messages.Chat; + import com.shephertz.appwarp.messages.LiveRoom; + import com.shephertz.appwarp.messages.Lobby; + import com.shephertz.appwarp.messages.Move; + import com.shephertz.appwarp.messages.Room; + import com.shephertz.appwarp.types.ResultCode; + + import flash.text.TextField; + import flash.utils.ByteArray; + + public class AppWarpListener implements ConnectionRequestListener, RoomRequestListener, NotificationListener,ChatRequestListener + { + + private var _owner:AppWarpChatRoomDemo; + + public function AppWarpListener(owner:AppWarpChatRoomDemo) + { + _owner = owner; + } + + + public function onConnectDone(res:int):void + { + if(res == ResultCode.success) + { + _owner.appwarp.joinRoom(_owner.roomID); + } + else{ + _owner.outputTextField.text += "\nConnection Failed!"; + _owner.connectbtn.backgroundColor = _owner.BLACK; + _owner.chatBtn.backgroundColor = _owner.GREY; + _owner.disconnectbtn.backgroundColor = _owner.GREY; + } + } + + public function onDisConnectDone(res:int):void + { + _owner.outputTextField.text += "\nDisconnected!"; + _owner.userinputTextField.text = _owner.NAME_PROMPT; + _owner.userinputTextField.textColor = _owner.GREY; + _owner.connectbtn.backgroundColor = _owner.BLACK; + _owner.chatBtn.backgroundColor = _owner.GREY; + _owner.disconnectbtn.backgroundColor = _owner.GREY; + } + + + public function onSubscribeRoomDone(event:Room):void + { + if(event.result == ResultCode.success){ + _owner.outputTextField.text += "\nReady To Chat!"; + _owner.userinputTextField.text = _owner.CHAT_PROMPT; + _owner.userinputTextField.textColor = _owner.GREY; + _owner.chatBtn.backgroundColor = _owner.BLACK; + _owner.disconnectbtn.backgroundColor = _owner.BLACK; + } + else{ + _owner.outputTextField.text += "\nSubscribe Room Failed!"; + } + } + public function onUnsubscribeRoomDone(event:Room):void + { + } + + public function onJoinRoomDone(event:Room):void + { + if(event.result == ResultCode.success){ + _owner.appwarp.subscribeRoom(_owner.roomID); + } + else{ + _owner.outputTextField.text += "Room Join Failed!" + } + } + + public function onLeaveRoomDone(event:Room):void + { + } + + public function onGetLiveRoomInfoDone(event:LiveRoom):void + { + } + + public function onSetCustomRoomDataDone(event:LiveRoom):void + { + } + + public function onUpdatePropertiesDone(event:LiveRoom):void + { + } + + public function onLockPropertiesDone(result:int):void + { + + } + + public function onUnlockPropertiesDone(result:int):void + { + + } + + public function onSendChatDone(res:int):void + { + if(res != ResultCode.success){ + _owner.outputTextField.text += "\nonSendChatDone : "+res; + } + else{ + _owner.chatBtn.backgroundColor = _owner.BLACK; + _owner.userinputTextField.text = _owner.CHAT_PROMPT; + _owner.userinputTextField.textColor = _owner.GREY; + } + } + + public function onSendPrivateChatDone(res:int):void + { + + } + + public function onRoomCreated(event:Room):void + { + } + public function onRoomDestroyed(event:Room):void + { + } + public function onUserLeftRoom(event:Room, user:String):void + { + _owner.outputTextField.text += "\n"+user+" has left"; + } + public function onUserJoinedRoom(event:Room, user:String):void + { + _owner.outputTextField.text += "\n"+user+" has joined"; + } + public function onUserLeftLobby(event:Lobby, user:String):void + { + } + public function onUserJoinedLobby(event:Lobby, user:String):void + { + } + public function onChatReceived(event:Chat):void + { + _owner.outputTextField.text += "\n"+ event.sender+ ": " +event.chat; + } + public function onPrivateChatReceived(sender:String, message:String):void + { + + } + public function onUpdatePeersReceived(update:ByteArray):void + { + } + public function onUserChangeRoomProperties(room:Room, user:String,properties:Object, lockTable:Object):void + { + } + + public function onMoveCompleted(moveEvent:Move):void + { + + } + } +} \ No newline at end of file diff --git a/SpriteMoveDemo/.actionScriptProperties b/SpriteMoveDemo/.actionScriptProperties index 1ea73b4..5da60e4 100644 --- a/SpriteMoveDemo/.actionScriptProperties +++ b/SpriteMoveDemo/.actionScriptProperties @@ -1,59 +1,54 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SpriteMoveDemo/.settings/org.eclipse.core.resources.prefs b/SpriteMoveDemo/.settings/org.eclipse.core.resources.prefs index b214f49..08643e9 100644 --- a/SpriteMoveDemo/.settings/org.eclipse.core.resources.prefs +++ b/SpriteMoveDemo/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,3 @@ -#Tue Jul 02 16:47:19 IST 2013 -eclipse.preferences.version=1 -encoding/=utf-8 +#Wed Jul 24 10:07:02 CST 2013 +eclipse.preferences.version=1 +encoding/=utf-8 diff --git a/SpriteMoveDemo/src/AppWarpListener.as b/SpriteMoveDemo/src/AppWarpListener.as index 0ab8a0e..1797f03 100644 --- a/SpriteMoveDemo/src/AppWarpListener.as +++ b/SpriteMoveDemo/src/AppWarpListener.as @@ -1,149 +1,149 @@ -package -{ - import com.shephertz.appwarp.WarpClient; - import com.shephertz.appwarp.listener.ConnectionRequestListener; - import com.shephertz.appwarp.listener.NotificationListener; - import com.shephertz.appwarp.listener.RoomRequestListener; - import com.shephertz.appwarp.messages.Chat; - import com.shephertz.appwarp.messages.LiveRoom; - import com.shephertz.appwarp.messages.Lobby; - import com.shephertz.appwarp.messages.Move; - import com.shephertz.appwarp.messages.Room; - import com.shephertz.appwarp.types.ResultCode; - - import flash.utils.ByteArray; - - public class AppWarpListener implements ConnectionRequestListener, RoomRequestListener, NotificationListener - { - private var _owner:SpriteMoveDemo; - - public function AppWarpListener(owner:SpriteMoveDemo) - { - _owner = owner; - } - - - public function onConnectDone(res:int):void - { - if(res == ResultCode.success){ - WarpClient.getInstance().joinRoom(_owner.roomID); - WarpClient.getInstance().subscribeRoom(_owner.roomID); - } - else if(res == ResultCode.api_not_found || res == ResultCode.auth_error){ - _owner.updateStatus("Verify your api key and secret key"); - } - else if(res == ResultCode.connection_error){ - _owner.updateStatus("Network Error. Check your internet connectivity and retry."); - } - else{ - _owner.updateStatus("Unknown Error"); - } - } - - public function onDisConnectDone(res:int):void - { - } - - public function onSubscribeRoomDone(event:Room):void - { - } - - public function onUnsubscribeRoomDone(event:Room):void - { - } - - public function onJoinRoomDone(event:Room):void - { - if(event.result == ResultCode.success){ - _owner.updateStatus("Started! Use up/down arrows and click to shoot."); - } - else{ - _owner.updateStatus("Room join failed. Verify your room id."); - } - } - - public function onLeaveRoomDone(event:Room):void - { - } - - public function onGetLiveRoomInfoDone(event:LiveRoom):void - { - } - - public function onSetCustomRoomDataDone(event:LiveRoom):void - { - } - - public function onLockPropertiesDone(result:int):void - { - - } - - public function onUnlockPropertiesDone(result:int):void - { - - } - - public function onUpdatePropertiesDone(event:LiveRoom):void - { - } - - public function onRoomCreated(event:Room):void - { - } - - public function onRoomDestroyed(event:Room):void - { - } - - public function onUserLeftRoom(event:Room, user:String):void - { - } - - public function onUserJoinedRoom(event:Room, user:String):void - { - } - - public function onUserLeftLobby(event:Lobby, user:String):void - { - } - - public function onUserJoinedLobby(event:Lobby, user:String):void - { - } - - public function onPrivateChatReceived(sender:String, chat:String):void - { - - } - - public function onChatReceived(event:Chat):void - { - if(event.sender != _owner.localUsername){ - var xyArray:Array = event.chat.split(","); - var x:int = parseInt( xyArray[1]); - var y:int = parseInt( xyArray[2]); - if(xyArray[0] == "player"){ - _owner.moveRemotePlayer(x, y); - } - else if(xyArray[0] == "projectile"){ - _owner.moveRemoteProjectile(x, y); - } - } - } - - public function onUpdatePeersReceived(update:ByteArray):void - { - - } - - public function onUserChangeRoomProperties(room:Room, user:String, properties:Object, lockTable:Object):void - { - } - - public function onMoveCompleted(moveEvent:Move):void - { - - } - } -} \ No newline at end of file +package +{ + import com.shephertz.appwarp.WarpClient; + import com.shephertz.appwarp.listener.ConnectionRequestListener; + import com.shephertz.appwarp.listener.NotificationListener; + import com.shephertz.appwarp.listener.RoomRequestListener; + import com.shephertz.appwarp.messages.Chat; + import com.shephertz.appwarp.messages.LiveRoom; + import com.shephertz.appwarp.messages.Lobby; + import com.shephertz.appwarp.messages.Move; + import com.shephertz.appwarp.messages.Room; + import com.shephertz.appwarp.types.ResultCode; + + import flash.utils.ByteArray; + + public class AppWarpListener implements ConnectionRequestListener, RoomRequestListener, NotificationListener + { + private var _owner:SpriteMoveDemo; + + public function AppWarpListener(owner:SpriteMoveDemo) + { + _owner = owner; + } + + + public function onConnectDone(res:int):void + { + if(res == ResultCode.success){ + WarpClient.getInstance().joinRoom(_owner.roomID); + WarpClient.getInstance().subscribeRoom(_owner.roomID); + } + else if(res == ResultCode.api_not_found || res == ResultCode.auth_error){ + _owner.updateStatus("Verify your api key and secret key"); + } + else if(res == ResultCode.connection_error){ + _owner.updateStatus("Network Error. Check your internet connectivity and retry."); + } + else{ + _owner.updateStatus("Unknown Error"); + } + } + + public function onDisConnectDone(res:int):void + { + } + + public function onSubscribeRoomDone(event:Room):void + { + } + + public function onUnsubscribeRoomDone(event:Room):void + { + } + + public function onJoinRoomDone(event:Room):void + { + if(event.result == ResultCode.success){ + _owner.updateStatus("Started! Use up/down arrows and click to shoot."); + } + else{ + _owner.updateStatus("Room join failed. Verify your room id."); + } + } + + public function onLeaveRoomDone(event:Room):void + { + } + + public function onGetLiveRoomInfoDone(event:LiveRoom):void + { + } + + public function onSetCustomRoomDataDone(event:LiveRoom):void + { + } + + public function onLockPropertiesDone(result:int):void + { + + } + + public function onUnlockPropertiesDone(result:int):void + { + + } + + public function onUpdatePropertiesDone(event:LiveRoom):void + { + } + + public function onRoomCreated(event:Room):void + { + } + + public function onRoomDestroyed(event:Room):void + { + } + + public function onUserLeftRoom(event:Room, user:String):void + { + } + + public function onUserJoinedRoom(event:Room, user:String):void + { + } + + public function onUserLeftLobby(event:Lobby, user:String):void + { + } + + public function onUserJoinedLobby(event:Lobby, user:String):void + { + } + + public function onPrivateChatReceived(sender:String, chat:String):void + { + + } + + public function onChatReceived(event:Chat):void + { + if(event.sender != _owner.localUsername){ + var xyArray:Array = event.chat.split(","); + var x:int = parseInt( xyArray[1]); + var y:int = parseInt( xyArray[2]); + if(xyArray[0] == "player"){ + _owner.moveRemotePlayer(x, y); + } + else if(xyArray[0] == "projectile"){ + _owner.moveRemoteProjectile(x, y); + } + } + } + + public function onUpdatePeersReceived(update:ByteArray):void + { + + } + + public function onUserChangeRoomProperties(room:Room, user:String, properties:Object, lockTable:Object):void + { + } + + public function onMoveCompleted(moveEvent:Move):void + { + + } + } +} diff --git a/SpriteMoveDemo/src/SpriteMoveDemo.as b/SpriteMoveDemo/src/SpriteMoveDemo.as index 182ab5e..c793f97 100644 --- a/SpriteMoveDemo/src/SpriteMoveDemo.as +++ b/SpriteMoveDemo/src/SpriteMoveDemo.as @@ -1,231 +1,231 @@ -var GREY:uint = 0x999999; -var BLACK:uint = 0x000000; -var WHITE:uint = 0xFFFFFF; -var RED:uint = 0xDF0101; - -package -{ - import com.shephertz.appwarp.WarpClient; - import com.shephertz.appwarp.types.ConnectionState; - - import flash.display.Sprite; - import flash.display.Stage; - import flash.display.StageAlign; - import flash.display.StageScaleMode; - import flash.events.Event; - import flash.events.KeyboardEvent; - import flash.events.MouseEvent; - import flash.text.TextField; - import flash.text.TextFormat; - import flash.text.TextFormatAlign; - import flash.ui.Keyboard; - - [SWF(backgroundColor="0xBDBDBD", width="500", height="400",)] - public class SpriteMoveDemo extends Sprite - { - private var localPlayer:Sprite; - private var remotePlayer:Sprite; - private var localProjectile:Sprite; - private var remoteProjectile:Sprite; - - private var isProjectileMoving:Boolean = false; - private var isRemoteProjectileMoving:Boolean = false; - private var connectbtn:TextField = new TextField(); - private var localDestinationY:int; - - private var remoteDestinationY:int; - - // AppWarp String Constants - public var localUsername:String; - public var roomID:String = "1799555827"; - private var apiKey:String = "b29f4030aba3b2bc7002c4eae6815a4130c862c386e43ae2a0a092b27de1c5af" - private var secretKey:String = "bf45f27e826039754f8dda659166d59ffb7b9dce830ac51d6e6b576ae4b26f7e"; - - private const WIDTH:int = 500; - private const HEIGHT:int = 400; - - private var listener:AppWarpListener; - - public function SpriteMoveDemo() - { - stage.scaleMode = StageScaleMode.NO_SCALE; - stage.align = StageAlign.TOP_LEFT - localPlayer = createAvatar(0xFFFF00) // size, color yellow - localPlayer.x = 0; - localPlayer.y = HEIGHT/2; - addChild(localPlayer); - - remotePlayer = createAvatar(0xFF0000) // size, color red - remotePlayer.x = WIDTH; - remotePlayer.y = HEIGHT/2; - addChild(remotePlayer); - - localProjectile = createProjectile(0xFFFF00); - localProjectile.y = HEIGHT/2; - localDestinationY = HEIGHT/2; - localProjectile.x = 0; - - remoteProjectile = createProjectile(0xFF0000); - remoteProjectile.x = WIDTH; - remoteProjectile.y = HEIGHT/2; - remoteDestinationY = HEIGHT/2; - - addChild(localProjectile); - addChild(remoteProjectile); - - addConnectButton(); - - stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedDown); - stage.addEventListener(MouseEvent.CLICK, onMouseClick); - - listener = new AppWarpListener(this); - - WarpClient.initialize(apiKey, secretKey); - - WarpClient.getInstance().setConnectionRequestListener(listener); - WarpClient.getInstance().setRoomRequestListener(listener); - WarpClient.getInstance().setNotificationListener(listener); - - localUsername = Math.random().toString(); - //WarpClient.getInstance().connect(localUsername); - } - - private function onMouseClick(e:MouseEvent):void - { - if(WarpClient.getInstance().getConnectionState() == ConnectionState.connected){ - if(isProjectileMoving == false) - { - WarpClient.getInstance().sendChat("projectile,"+e.localX+","+e.localY); - isProjectileMoving = true; - localProjectile.y = e.localY; - } - } - } - - private function drawprojectile(event:Event):void - { - updateLocalProjectile(); - updateRemoteProjectile(); - } - - private function updateLocalProjectile():void - { - if(isProjectileMoving){ - localProjectile.x += 10; - } - if(localProjectile.x >= WIDTH){ - localProjectile.x = -5; - isProjectileMoving = false; - } - } - - private function keyPressedDown(event:KeyboardEvent):void { - - if(WarpClient.getInstance().getConnectionState() != ConnectionState.connected){ - return; - } - var key:uint = event.keyCode; - var step:uint = 15; - switch (key) { - case Keyboard.UP : - localPlayer.y -= step; - WarpClient.getInstance().sendChat("player,"+localPlayer.x+","+localPlayer.y); - break; - case Keyboard.DOWN : - localPlayer.y += step; - WarpClient.getInstance().sendChat("player,"+localPlayer.x+","+localPlayer.y); - break; - default: - break; - } - } - - public function moveRemotePlayer(x:int, y:int):void - { - remotePlayer.y = y; - - } - - public function moveRemoteProjectile(x:int, y:int):void - { - remoteProjectile.x = WIDTH; - remoteProjectile.y = y; - isRemoteProjectileMoving = true; - - } - - private function updateRemoteProjectile():void - { - if(isRemoteProjectileMoving){ - remoteProjectile.x -= 10; - } - if(remoteProjectile.x <= 0){ - remoteProjectile.x = WIDTH+5; - isRemoteProjectileMoving = false; - } - } - - private function createAvatar(bgColor:uint):Sprite { - var s:Sprite = new Sprite(); - s.graphics.beginFill(bgColor); - s.graphics.drawCircle(0, 0, 40); - s.graphics.endFill(); - s.graphics.beginFill(0x000000); - s.graphics.drawCircle(-15, -10, 5); - s.graphics.drawCircle(+15, -10, 5); - s.graphics.endFill(); - s.graphics.lineStyle(2, 0x000000, 100); - s.graphics.moveTo(-20,15); - //this will define the start point of the curve - s.graphics.curveTo(0,35, 20,15); - //the first two numbers are your control point for the curve - //the last two are the end point of the curve - return s; - } - - private function createProjectile(color:uint):Sprite { - var s:Sprite = new Sprite(); - s.graphics.beginFill(color); - s.graphics.drawCircle(0, 0, 10); - s.graphics.endFill(); - s.addEventListener(Event.ENTER_FRAME, drawprojectile); - return s; - } - - private function addConnectButton():void{ - - var headerFormat:TextFormat = new TextFormat(); - headerFormat.size = 20; - headerFormat.bold = true; - headerFormat.align = TextFormatAlign.CENTER; - - connectbtn.defaultTextFormat = headerFormat; - connectbtn.y = 5; - connectbtn.x = 0; - connectbtn.selectable = false; - connectbtn.width = 500; - connectbtn.height = 25; - connectbtn.background = true; - connectbtn.backgroundColor = 0x000000; - connectbtn.textColor = 0xFFFFFF; - connectbtn.text = "Start Game"; - connectbtn.addEventListener(MouseEvent.CLICK,connect_click); - addChild(connectbtn); - } - - - private function connect_click(e:MouseEvent):void - { - if(WarpClient.getInstance().getConnectionState() == ConnectionState.disconnected) - { - WarpClient.getInstance().connect(localUsername); - connectbtn.text = "Connecting.."; - } - } - - public function updateStatus(message:String):void - { - connectbtn.text = message; - } - } +package +{ + import com.shephertz.appwarp.WarpClient; + import com.shephertz.appwarp.types.ConnectionState; + + import flash.display.Sprite; + import flash.display.Stage; + import flash.display.StageAlign; + import flash.display.StageScaleMode; + import flash.events.Event; + import flash.events.KeyboardEvent; + import flash.events.MouseEvent; + import flash.text.TextField; + import flash.text.TextFormat; + import flash.text.TextFormatAlign; + import flash.ui.Keyboard; + + [SWF(backgroundColor="0xBDBDBD", width="500", height="400")] + public class SpriteMoveDemo extends Sprite + { + private static const GREY:uint = 0x999999; + private static const BLACK:uint = 0x000000; + private static const WHITE:uint = 0xFFFFFF; + private static const RED:uint = 0xDF0101; + + private var localPlayer:Sprite; + private var remotePlayer:Sprite; + private var localProjectile:Sprite; + private var remoteProjectile:Sprite; + + private var isProjectileMoving:Boolean = false; + private var isRemoteProjectileMoving:Boolean = false; + private var connectbtn:TextField = new TextField(); + private var localDestinationY:int; + + private var remoteDestinationY:int; + + // AppWarp String Constants + public var localUsername:String; + public var roomID:String = "1799555827"; + private var apiKey:String = "b29f4030aba3b2bc7002c4eae6815a4130c862c386e43ae2a0a092b27de1c5af" + private var secretKey:String = "bf45f27e826039754f8dda659166d59ffb7b9dce830ac51d6e6b576ae4b26f7e"; + + private const WIDTH:int = 500; + private const HEIGHT:int = 400; + + private var listener:AppWarpListener; + + public function SpriteMoveDemo() + { + stage.scaleMode = StageScaleMode.NO_SCALE; + stage.align = StageAlign.TOP_LEFT + localPlayer = createAvatar(0xFFFF00) // size, color yellow + localPlayer.x = 0; + localPlayer.y = HEIGHT/2; + addChild(localPlayer); + + remotePlayer = createAvatar(0xFF0000) // size, color red + remotePlayer.x = WIDTH; + remotePlayer.y = HEIGHT/2; + addChild(remotePlayer); + + localProjectile = createProjectile(0xFFFF00); + localProjectile.y = HEIGHT/2; + localDestinationY = HEIGHT/2; + localProjectile.x = 0; + + remoteProjectile = createProjectile(0xFF0000); + remoteProjectile.x = WIDTH; + remoteProjectile.y = HEIGHT/2; + remoteDestinationY = HEIGHT/2; + + addChild(localProjectile); + addChild(remoteProjectile); + + addConnectButton(); + + stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedDown); + stage.addEventListener(MouseEvent.CLICK, onMouseClick); + + listener = new AppWarpListener(this); + + WarpClient.initialize(apiKey, secretKey); + + WarpClient.getInstance().setConnectionRequestListener(listener); + WarpClient.getInstance().setRoomRequestListener(listener); + WarpClient.getInstance().setNotificationListener(listener); + + localUsername = Math.random().toString(); + //WarpClient.getInstance().connect(localUsername); + } + + private function onMouseClick(e:MouseEvent):void + { + if(WarpClient.getInstance().getConnectionState() == ConnectionState.connected){ + if(isProjectileMoving == false) + { + WarpClient.getInstance().sendChat("projectile,"+e.localX+","+e.localY); + isProjectileMoving = true; + localProjectile.y = e.localY; + } + } + } + + private function drawprojectile(event:Event):void + { + updateLocalProjectile(); + updateRemoteProjectile(); + } + + private function updateLocalProjectile():void + { + if(isProjectileMoving){ + localProjectile.x += 10; + } + if(localProjectile.x >= WIDTH){ + localProjectile.x = -5; + isProjectileMoving = false; + } + } + + private function keyPressedDown(event:KeyboardEvent):void { + + if(WarpClient.getInstance().getConnectionState() != ConnectionState.connected){ + return; + } + var key:uint = event.keyCode; + var step:uint = 15; + switch (key) { + case Keyboard.UP : + localPlayer.y -= step; + WarpClient.getInstance().sendChat("player,"+localPlayer.x+","+localPlayer.y); + break; + case Keyboard.DOWN : + localPlayer.y += step; + WarpClient.getInstance().sendChat("player,"+localPlayer.x+","+localPlayer.y); + break; + default: + break; + } + } + + public function moveRemotePlayer(x:int, y:int):void + { + remotePlayer.y = y; + + } + + public function moveRemoteProjectile(x:int, y:int):void + { + remoteProjectile.x = WIDTH; + remoteProjectile.y = y; + isRemoteProjectileMoving = true; + + } + + private function updateRemoteProjectile():void + { + if(isRemoteProjectileMoving){ + remoteProjectile.x -= 10; + } + if(remoteProjectile.x <= 0){ + remoteProjectile.x = WIDTH+5; + isRemoteProjectileMoving = false; + } + } + + private function createAvatar(bgColor:uint):Sprite { + var s:Sprite = new Sprite(); + s.graphics.beginFill(bgColor); + s.graphics.drawCircle(0, 0, 40); + s.graphics.endFill(); + s.graphics.beginFill(0x000000); + s.graphics.drawCircle(-15, -10, 5); + s.graphics.drawCircle(+15, -10, 5); + s.graphics.endFill(); + s.graphics.lineStyle(2, 0x000000, 100); + s.graphics.moveTo(-20,15); + //this will define the start point of the curve + s.graphics.curveTo(0,35, 20,15); + //the first two numbers are your control point for the curve + //the last two are the end point of the curve + return s; + } + + private function createProjectile(color:uint):Sprite { + var s:Sprite = new Sprite(); + s.graphics.beginFill(color); + s.graphics.drawCircle(0, 0, 10); + s.graphics.endFill(); + s.addEventListener(Event.ENTER_FRAME, drawprojectile); + return s; + } + + private function addConnectButton():void{ + + var headerFormat:TextFormat = new TextFormat(); + headerFormat.size = 20; + headerFormat.bold = true; + headerFormat.align = TextFormatAlign.CENTER; + + connectbtn.defaultTextFormat = headerFormat; + connectbtn.y = 5; + connectbtn.x = 0; + connectbtn.selectable = false; + connectbtn.width = 500; + connectbtn.height = 25; + connectbtn.background = true; + connectbtn.backgroundColor = 0x000000; + connectbtn.textColor = 0xFFFFFF; + connectbtn.text = "Start Game"; + connectbtn.addEventListener(MouseEvent.CLICK,connect_click); + addChild(connectbtn); + } + + + private function connect_click(e:MouseEvent):void + { + if(WarpClient.getInstance().getConnectionState() == ConnectionState.disconnected) + { + WarpClient.getInstance().connect(localUsername); + connectbtn.text = "Connecting.."; + } + } + + public function updateStatus(message:String):void + { + connectbtn.text = message; + } + } } \ No newline at end of file