Discussion list for Unity developers.
unity-dev at moock.org
Mon Jan 29 09:00:38 CST 2007
Thank you very much!
Everything is working now!
~Tony
-----Original Message-----
From: unity-dev-bounces at moock.org [mailto:unity-dev-bounces at moock.org]
On Behalf Of Discussion list for Unity developers.
Sent: Sunday, January 28, 2007 3:13 AM
To: unity-dev at moock.org
Subject: Re: ||unity-dev|| newbie question on extending uSharedPointer
hi tony,
the instance variable 'client' is null because it is not available in
the scope of the nested onRelease() function. (just to be clear, this is
an ActionScript 2.0 issue, not a Unity issue).
in onAddClient(), try creating a new local variable to hold the
reference to 'client', as in:
var thisClient:UClient = client;
then, within onRelease(), you should be able to do this:
thisClient.invokeOnClient("onClick", clientID, s);
the preceding code works because a nested function has access to its
parent function's local variables via the scope chain.
hope that helps,
colin
Discussion list for Unity developers. wrote:
> Hi Unity developers,
>
>
>
> My name is Tony. I just joined this list. Please forgive my
> unfamiliarity with Unity.
>
>
>
> I'm very new to Unity development (first time). I'm currently working
> on a project that is pretty much the uSharedPointer example with the
> addition of one thing:
>
> When a user's pointer is clicked on, that particular user gets a
visual
> cue.
>
> Ex. Users A and B are on the visiting the site. User A clicks on User
> B's mouse cursor which in turn causes a visual cue on User B's flash.
>
>
>
> I've modified the SharedPointerRoomView class:
>
>
>
> public function onNumClients (e:URoomEvent):Void {
>
> client.getTargetMC().numUsers_txt.text = e.getNumClients() + ' ('
+
> client.getClientID() + ')';
>
> //client.invokeOnClient("onClick", client.getClientID(),
> client.getClientID());
>
> trace(e.getNumClients());
>
> }
>
>
>
> public function onAddClient (e:URoomEvent):Void {
>
> var clientID:String = e.getClientID();
>
> var username:String;
>
>
>
> // Retrieve the remoteuser that represents the client that just
> joined.
>
> var remoteuser:RemoteClient =
> client.getRemoteClientManager().getClient(clientID);
>
>
>
> // Create a Pointer object for the new user.
>
> pointers[clientID] = new Pointer(client.getTargetMC(),
> client.getNewTargetDepth());
>
> pointers[clientID].setIcon(Settings.defaultPointerIcon);
>
> var s:String = client.getClientID();
>
> // hide your own pointer
>
> if (clientID == s)
>
> { pointers[clientID].hide(); }
>
> pointers[clientID].pointerContainer_mc.onRelease = function ()
>
> {
>
> //client.invokeOnClient("onClick", clientID, s);
>
> //var ev:URoomEvent = new URoomEvent(this, clientID, s);
>
> //this.onClick(ev);
>
> //trace(ev.getStatus());
>
> }
>
>
>
> var userPositions:Array =
> remoteuser.getAttribute(Settings.appNamespaceID
>
> + "."
+
> Settings.appRoomID, "posList").split("~");
>
> var userNextPosition:Array = userPositions[0].split(",");
>
> var userX:Number = parseInt(userNextPosition[0]);
>
> var userY:Number = parseInt(userNextPosition[1]);
>
>
>
> client.invokeOnClient("setClickerEvent", client.getClientID(),
> client.getClientID());
>
>
>
> pointers[clientID].moveTo(userX, userY);
>
> }
>
>
>
> /**
>
> * URoomListener event handler
>
> */
>
> public function onClick(e:URoomEvent):Void {
>
> trace(client.getClientID() + ' to ' + e.getStatus());
>
> client.invokeOnClient("onClick", e.getStatus(),
> client.getClientID());
>
> }
>
>
>
>
>
> I've also added this event handler to uSharedPointer class:
>
>
>
> public function onClick(e:SocketEvent):Void {
>
> trace(e);
>
> if (getClientID() == e)
>
> {
>
> getTargetMC().showClicker();
>
> }
>
> }
>
>
>
>
>
> The problem is that the client variable is null when the onRelease
event
> is triggered. The invokeOnClient() call works in the onNumClients()
> event handler. I tried to raise an event but that didn't work, also.
> So I'm stuck. Maybe I'm overlooking the obvious.
>
> Please help.
>
>
>
> Thank you very much for your time!
>
> ~Tony
>
>
>
> --
> you're a unity-dev subscriber. to unsubscribe, visit
www.moock.org/mailman/listinfo/unity-dev/
>
> superb hosting for this list and moock.org is generously provided by
Rackspace. See: http://www.rackspace.com/?supbid=moock
--
you're a unity-dev subscriber. to unsubscribe, visit
www.moock.org/mailman/listinfo/unity-dev/
superb hosting for this list and moock.org is generously provided by
Rackspace. See: http://www.rackspace.com/?supbid=moock