Forum ActionScript 3.0 getting a reference to the client or connection

Problems and discussions relating to ActionScript 3.0 here.

getting a reference to the client or connection

Postby truefire » November 24th, 2010, 6:37 am

I'm trying to get a reference to the client and connection on the stage/root/whatever, so that I can easily access it anywhere in my game. I've found a workaround for the connection, but none of my attempts have successfully worked for client. The only place I can access it, as of now, is in my handleConnect() function. So how would I go about getting a reference to the client where I can easily access it. (Also, how would I do that for connection? My current way works well enough, but it's an obvious workaround, so I'd like to do it a simpler way if possible).

Thanks in advance for any help.
truefire
 
Posts: 15
Joined: November 22nd, 2010, 6:01 am

Re: getting a reference to the client or connection

Postby default0 » November 24th, 2010, 9:40 am

truefire wrote:I'm trying to get a reference to the client and connection on the stage/root/whatever, so that I can easily access it anywhere in my game. I've found a workaround for the connection, but none of my attempts have successfully worked for client. The only place I can access it, as of now, is in my handleConnect() function. So how would I go about getting a reference to the client where I can easily access it. (Also, how would I do that for connection? My current way works well enough, but it's an obvious workaround, so I'd like to do it a simpler way if possible).

Thanks in advance for any help.


public var GlobalClient:Client;
public function handleConnect(client:Client):void
{
GlobalClient = client;
trace("Reference created");
}

You're done. Same for connection...

EDIT: To access connection/client from another movieclip on your stage, go like this:
Code: Select all
public class MC extends MovieClip
{
    public var Root:DocumentClass;
    function MC()
    {
        this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    }
    public function onAddedToStage(e:Event):void
    {
        this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        Root = DocumentClass(root);

        Root.GlobalConnection.send("blah", "blubb");
    }
}



Best regards
Try to play my Game: -->BlackGalaxy<--
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany

Re: getting a reference to the client or connection

Postby batiali » November 24th, 2010, 12:19 pm

What I'm doing is to store it in a static variable within my document class and set it in handleConnect listener function.

Code: Select all
public static var client:Client;
batiali
 
Posts: 29
Joined: August 11th, 2010, 2:53 pm

Re: getting a reference to the client or connection

Postby truefire » December 1st, 2010, 3:19 pm

Yeah, thanks. That's what I had been trying, with no success. Turns out, It was capitalization. I was using the C# "BigDB", rather than the AS3 "bigDB"...
truefire
 
Posts: 15
Joined: November 22nd, 2010, 6:01 am


Return to ActionScript 3.0