# \[Flash8\] AS2 and Socket Server

**URL:** <https://forum.kirupa.com/t/flash8-as2-and-socket-server/310252>\
**Category:** flash\
**Created:** [June 5, 2010, 8:16pm UTC](https://forum.kirupa.com/t/flash8-as2-and-socket-server/310252 "2010-06-05T20:16:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![capdetrons](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@capdetrons](https://forum.kirupa.com/u/capdetrons)\
**Post date:** [June 5, 2010, 8:16pm UTC](https://forum.kirupa.com/t/flash8-as2-and-socket-server/310252/1 "2010-06-05T20:16:26Z")

</div>

Hi, again,

I hadn’t ckecked the forum in a couple of days and managed to get the hitTest working in my application. It works, but only one way: the user in clipA attaches the movieclip, but the other or others, won’t.  
I would need to update the move somehow updating something but, I don’t understand much, because the avatar in the second client does move to the choords as they are updated.  
Does anyone know about electroserver? I cannot get the sendMove method working either…

var users:Object = {};  
var clip\_arr:Array = new Array();  
var clipMan:Array = new Array();  
var clipWoman:Array = new Array();  
var all:Array = clip\_arr;  
createAvatar(myUsername, gender, Math.ceil(Math.random()_(board.\_width-30)), Math.ceil(Math.random()_(board.\_height-30)));  
createUserVariables();  
function createUserVariables():Void {  
es.createUserVariable(“gender”, gender);  
es.createUserVariable(“coords”, users[myUsername].x+","+users[myUsername].y);  
}  
initMouseControl();  
initTweens();  
showUsers();  
showRooms();  
function initMouseControl():Void {  
board.onPress = function():Void {  
mouseClicked();  
};  
board.useHandCursor = false;  
}  
function initTweens():Void {  
this.onEnterFrame = moveAvatars;  
}  
function showUsers(userlist:Array, type:String, lastUser:String):Void {  
if (userlist == undefined) {  
userlist = es.getUserList();  
}  
userListBox.dataProvider = userlist;  
switch (type) {  
case “userjoined” :  
createAvatar(lastUser);  
break;  
case “userleft” :  
deleteAvatar(lastUser);  
break;  
case “all” :  
case undefined :  
createAllAvatars(userlist);  
break;  
}  
for (var i in userlist) {  
var user:Object = userlist\*;  
var username:String = user.Name.value;  
var temp:Array = user.userVariables.coords.split(",");  
users[username].x = temp[0];  
users[username].y = temp[1];  
users[username].gender = user.userVariables.gender;  
}  
updateAvatars();  
}

es.userListUpdated = showUsers;  
es.userVariableUpdated = userVariableUpdated;  
function userVariableUpdated(user:Object, type:String, name:String):Void {  
var username:String = user.Name.value;  
if (username == myUsername) {  
return;  
}  
switch (name) {  
case “gender” :  
users[username].gender = user.userVariables.gender;  
users[username].clip.gotoAndStop(user.userVariables.gender);  
break;  
case “coords” :  
var temp:Array = user.userVariables.coords.split(",");  
userPositionUpdated(username, temp[0], temp[1]);  
break;  
}  
}  
function createAllAvatars(userlist:Array):Void {  
for (var i in userlist) {  
var username:String = userlist\*.Name.value;  
var gender:String = userlist\*.userVariables.gender;  
var x:Number = userlist\*.userVariables.x;  
var y:Number = userlist\*.userVariables.y;  
createAvatar(username, gender, x, y);  
}  
}  
function userPositionUpdated(username:String, newX:Number, newY:Number):Void {  
users[username].sourceX = users[username].x;  
users[username].sourceY = users[username].y;  
users[username].x = newX;  
users[username].y = newY;  
}  
function createAvatar(username:String, gender:String, x:Number, y:Number):Void {  
if (users[username] != undefined) {  
return;  
}  
users[username] = {};  
var user:Object = users[username];  
user.clip = board.attachMovie(“smiley”, username, board.getNextHighestDepth());  
user.clip.gotoAndStop(gender);  
user.x = user.clip.\_x=x;  
user.y = user.clip.\_y=y;  
user.clip.username\_txt.text = username;  
user.gender = gender;  
if(gender == “home”){  
clipMan.push(user.clip);  
} else {  
clipWoman.push(user.clip);  
}  
clip\_arr.push(user.clip);  
}  
function deleteAvatar(username:String):Void {  
removeMovieClip(users[username].clip);  
delete users[username];  
}  
function updateAvatars():Void {  
for (var i in users) {  
var user:Object = users\*;  
if (user.x != undefined && user.y != undefined) {  
user.clip.\_x = user.x;  
user.clip.\_y = user.y;  
}  
}  
}  
function mouseClicked():Void {  
var newX:Number = \_root.\_xmouse-board.\_x;  
var newY:Number = \_root.\_ymouse-board.\_y;  
var x:Number = users[myUsername].x;  
var y:Number = users[myUsername].y;  
users[myUsername].sourceX = x;  
users[myUsername].sourceY = y;  
users[myUsername].x = newX;  
users[myUsername].y = newY;  
detectCollision();  
es.updateUserVariable(“coords”, newX+","+newY);  
}  
function moveAvatars():Void {  
for (var i:String in users) {  
var user:Object = users\*;  
var clip:MovieClip = user.clip;  
var floor:Function = Math.floor;  
clip.\_x += (user.x-clip.\_x)/6;  
clip.\_y += (user.y-clip.\_y)/6;  
}  
}  
function detectCollision():Void{  
for(i=0;i\<clip\_arr.length;i++){  
clipA = clipMan\*;  
clipB = clipWoman\*;  
if(clipA.hitTest(clipB)){  
this.clipA.\_visible = false;  
this.clipB.\_visible = false;  
attachMovie(“hugs”, “hugs”, this.getNextHighestDepth(), {\_x:\_xmouse, \_y:\_ymouse});  
}  
}  
}
