As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/

Actionscript 2.0, Objects, MovieClip Event Handlers, etc

JasconiusJasconius sword criminalmad onlineRegistered User regular
edited November 2007 in Help / Advice Forum
OK guys, here is the deal.

I have a generic Object that I am storing a small dataset in (x and y value of a movieclip). I need to sync this Object with a SharedObject for Flash Media Server 2, but it needs to be done inside of a series of MovieClip event handlers.

The code is below, I tried to cut out as much irrelevant stuff as possible.

The object gets created, and I can successfully handle and trace it's values outside of event handlers.

Jump down to /* Pointer Handling */ and you can see that final trace before the series of event handlers.

Right now I have the actual syncing going on inside of a separate function but even if I just throw it inside of the onMouseMove, the result is the same.

The sync itself is valid, if I were to pass text in instead of the object or one of the object properties it would work fine.

Any attempt to reference the pointerLocation object within those event handlers fails. I tried passing pointerLocation into the functions a la

mc_pointer.onMouseDown = function(pointerLocation):Void

to no avail.

I've tried the same thing with an Array just to make sure it wasn't incompatible with generic objects and it did the same thing.

I really need to sync this data (x and y) at the same time, because if I sync X and Y independently then it just rapes the connections and things go out of sync because the onSync operations are too large to handle in time.

On that note, if anyone knows a good Flash Media Server 2 blog or web site, I would appreciate it, the Adobe manuals and even O'Reilly's book tend to be basic.
/* Global Variables and Objects */

var pointerLocation:Object = new Object();
pointerLocation.xcoord = 300;
pointerLocation.ycoord = 380;
/* Attach items n' stuff */

this.attachMovie("mc_pointer", "mc_pointer", this.getNextHighestDepth(), {_x:pointerLocation.xcoord, _y:pointerLocation.ycoord});
trace(pointerLocation);

/* Create Net Connection */
var rtmpNow = "rtmp:/superchat";
//var rtmpNow = "rtmp://superchat";
var nc:NetConnection = new NetConnection();
nc.onStatus = function(info):Void 
{
	trace(info.code);
	//txt_output.text = info.code;
};
nc.connect(rtmpNow);
/* Shared Object Farm */

var so_pointer:SharedObject = SharedObject.getRemote("so_pointer", nc.uri, false);

so_pointer.connect(nc);

/* Shared Object Sync */

so_pointer.onSync = function():Void 
{
	//Pointer has moved
	//trace(so_pointer.data.owner);
	pointerLocation = so_pointer.data.coords;
	/*trace(so_pointer.data.coords);
	trace(pointerLocation);
	trace(pointerLocation.xcoord);
	trace(pointerLocation.ycoord);*/
	mc_pointer._x = pointerLocation.xcoord;
	mc_pointer._y = pointerLocation.ycoord;
	if (mc_pointer._alpha == 0)
	{
		mc_pointer._alpha = 100;
	}
	if (so_pointer.data.owner == mc_pointer.txt_pointer.text)
	{
		//The owner is the same as it was last time, do nothing
	}
	else
	{
		//New owner or unowned, set new text
		if (so_pointer.data.owner == undefined || so_pointer.data.owner == "")
		{
			mc_pointer.txt_pointer.text = "Click + Drag";
			mc_pointer.txt_pointer.setTextFormat(fmt_white);
		}
		else
		{
			mc_pointer.txt_pointer.text = so_pointer.data.owner;
			mc_pointer.txt_pointer.setTextFormat(fmt_white);
		}
	}
};

/* Pointer Handling */
trace(pointerLocation + "right before");
function updateLocation():Void
{
	trace(pointerLocation + "inside");
	pointerLocation.xcoord = mc_pointer._x;
	pointerLocation.ycoord = mc_pointer._y;
	so_pointer.data.coords = pointerLocation;
}
mc_pointer.onRollOver = function():Void 
{
	mc_pointer.onMouseDown = function():Void 
	{
		if (so_pointer.data.owner == undefined || so_pointer.data.owner == "")
		{
			so_pointer.data.owner = txt_username.text;
			mc_pointer.startDrag();
			this.onMouseMove = function():Void 
			{
				updateLocation();
			};
		}
	};
};
mc_pointer.onMouseUp = function():Void 
{
	mc_pointer.stopDrag();
	this.onMouseMove = null;
	if (so_pointer.data.owner == txt_username.text)
	{
		so_pointer.data.owner = "";
	}
};
mc_pointer.onRollOut = function():Void 
{
	mc_pointer.onMouseDown = null;
};

Jasconius on
Sign In or Register to comment.