I’m trying to make my own Avatar chat.
For some reason in one of my movie clips, when I use
onClipEvent(mouseUp)
{
}
it seems to call it self exponentially depending on how many times I’ve clicked.
ex.
When I click once, it gets called once
When I click twice, it gets called 2 times
3 -> 4
4 -> 16
etc…
I tried debugging it but can’t find the reason for this redundant call to itself.
Heres the code:
This is inside the movie clip
onClipEvent(load)
{
if(_name != "container")
{
//if name isn't main container
//then initialize variables
_x = 275;
_y = 200;
var newX:Number = _x;
var newY:Number = _y;
}
}
onClipEvent(mouseUp)
{
if(_name != "container")
{
//if name isn't main container
//declare variable vector
var vector:Array = new Array();
//get new mouse coordinates
newX = _root._xmouse;
newY = _root._ymouse;
//set up vector
vector[0] = name+"Avatar";
vector[1] = newX;
vector[2] = newY;
vector[3] = false;
//send vector to server to be echoed
_root.socket.send(vector);
_root.socket.send("
");
}
}
onClipEvent(enterFrame)
{
//eases to new spot
_x += (newX-_x)/5;
_y += (newY-_y)/5;
}
This is inside the frame
//declares variables
var socket:XMLSocket = new XMLSocket();
var name:String = "";
var depths:Number = 1;
var nameList:Array = new Array();
socket.onConnect = function(success)
{
//if connection to server was successful
if(success)
{
//declare vector array
var vector:Array = new Array();
//trace that it's connected
trace("Connected");
//duplicate a container and call it your username+"Avatar"
_root.container.duplicateMovieClip(name+"Avatar", depths);
//attach a movie to your new container
_root[name+"Avatar"].attachMovie("avatar", "avatar"+depths, depths);
//increase depth
depths++;
//fill vector
vector[0] = name+"Avatar";
vector[1] = _root[name+"Avatar"]._x;
vector[2] = _root[name+"Avatar"]._y;
vector[3] = true;
//send vector to server
socket.send(vector);
socket.send("
");
}
else
//if couldn't connect, trace that it's not connected
trace("Not Connected");
}
socket.onClose = function()
{
//if server is closed, trace connection lost
trace("Connection Lost");
}
//when receives data from server
XMLSocket.prototype.onData = function(msg)
{
//declare variables
var vector:Array = new Array();
//takes message from server and splits it by the comma's
vector = msg.split(",");
//traces new vector
trace(vector);
//if whats received is not your avatar
if(vector[0] != name+"Avatar")
{
//checks to see if it is a new avatar
if(vector[3] == true)
{
//if it is then push its name on the list
nameList.push(vector[0]);
//make new container for new avatar
_root.container.duplicateMovieClip(vector[0], depths);
//attach new avatar
_root[vector[0]].attachMovie("avatar", "avatar"+depths);
depths++;
}
//get newpositions for the new avatar
_root[vector[0]].newX = vector[1];
_root[vector[0]].newY = vector[2];
}
}
With it calling mouseUp exponentially, it sends the same message to the server many times, lagging the server.
Any help?
Thanks