Forum ActionScript 3.0 *SOLVED* connection.send();

Problems and discussions relating to ActionScript 3.0 here.

*SOLVED* connection.send();

Postby angelicstickman » June 17th, 2012, 3:49 pm

How do I use connection.send(); outside of the handleJoin(connection:Connection) function?

I have a function as follows:

Code: Select all
function keyPressed(e:KeyboardEvent):void
{
connection.send("Key Pressed");
}


This wont work because connection isn't part of this function, but if that's the case how can I use connection.send when a key is pressed. How would I call the handleJoin function without using PlayerIO.connect everytime?
Last edited by angelicstickman on June 18th, 2012, 1:05 pm, edited 1 time in total.
angelicstickman
 
Posts: 7
Joined: June 17th, 2012, 1:15 pm

Re: connection.send();

Postby dreamora » June 17th, 2012, 5:46 pm

you need to store the connection object you get in a global variable which you can access at any point in time.
dreamora
 
Posts: 225
Joined: March 2nd, 2012, 9:58 am

Re: connection.send();

Postby angelicstickman » June 17th, 2012, 6:14 pm

dreamora wrote:you need to store the connection object you get in a global variable which you can access at any point in time.


How would I do that? Also, I am not quite sure what is meant by connection object.
angelicstickman
 
Posts: 7
Joined: June 17th, 2012, 1:15 pm

Re: connection.send();

Postby dreamora » June 17th, 2012, 8:20 pm

Connection is a class.
You get instances of the Connection class, the connection object, from CreateJoinRoom function call which you do after you successfully connected the client with the Player.IO server
dreamora
 
Posts: 225
Joined: March 2nd, 2012, 9:58 am

Re: connection.send();

Postby angelicstickman » June 17th, 2012, 9:45 pm

dreamora wrote:Connection is a class.
You get instances of the Connection class, the connection object, from CreateJoinRoom function call which you do after you successfully connected the client with the Player.IO server


I don't understand, would you be able to give an example?
angelicstickman
 
Posts: 7
Joined: June 17th, 2012, 1:15 pm

Re: connection.send();

Postby angelicstickman » June 18th, 2012, 1:05 pm

Ah, I understand it now.

Create a variable which is an instance of the Connection class and set it to connection received in the handleJoin function!

Thanks very much :)
angelicstickman
 
Posts: 7
Joined: June 17th, 2012, 1:15 pm


Return to ActionScript 3.0



cron