Jim Lynch Codes
  • Blog
  • About Jim

Connect & Login Tutorial with Flash and Yahoo Games SDK (Player.io)


Login
And so it begins… A new framework. A new API, and all new method calls to learn and get used to and harness to create your own virtual experiences. But where does it all begin? In this tutorial we will take it all back to when your game first loads up. You’ll be using the Yahoo Games (Player.io) SDK so if you don’t have that yet check out Setting up: Flash Pro and Flash Builder and Setting Up a Player.io Flash Project.

So let’s get started! Once your game gets going and becomes popular you will probably want to add in Facebook and/or Kongregate authentication, but for this tutorial we’re going to keep it simple with standard username/password authentication.

You can also check out the official Yahoo documentation for getting started and logging in: https://gamesnet.yahoo.net/documentation/tutorials/flashcombopackage

So, when your game loads up you’re going to want to prompt the user to enter their username and password. You will also want some buttons and a container for everything. To make things easy on you and allow you to focus on the code, I’ve provided this basic login popup in a Flash Professional file. For help setting it up see Setting up a Flash Professional Project.

Once you have the fla set up and an actionscript file open you’re ready to start coding. Let’s begin with the guest login button.

It’s now time to introduce the mystical, magical method that allows your game to initiate a connection with the Yahoo Games network of servers. You will use this connection to send and receive messages for the life of the swf. And here's the method itself (!!!): Playerio.connect


public static connect (stage:flash.display:Stage, gameId:String, connectionId:String, userId:String, 
auth:String, partnerId:* = null, playerInsightSegments:* = null, callback:* = null, errorHandler:* = null):void


This method might seem a little intimidating at first since it takes 9 arguments, but we're going to go over them all right here. The first 5 are parameters that you pass in so it knows where and who to connect as, the next two you won't need right now as they deal with enhancing analytics and using PartnerPay. The last two are handler functions to be triggered when the connect method gets a response.

1) stage : flash.display.Stage - This is a reference to the Flash stage (see Easily Reference the Flash Stage from Anywhere)

2) Player.io Game Id : String - This is a unique string that corresponds to a game that you make in the Yahoo Games browser console.

3) ConnectionId : String - Playerio describes this as, "the id of the connection to use when connecting to the game". That's true, but it doesn't really say much. It really has to do with the type of authentication you want to use for checking the user's credentials. The Player.io documentation recommends using "public" here because this connectionId is always already there by default. You can use public or make your own and enter it's name in this parameter of the connect method. 
Picture
Here is what making a new connectionId looks like. I recommend using SimpleUsers login for username/password authentication.
Picture
SimpleUsers is our go-to username/password authentication. Facebook and Kongregate are the popular Player.io single sign on platforms, but there are also Yahoo (of course), Armor Games, and AdTrack. HTTP Webservice opens the door even further for authenticating through more exotic platforms.
Picture
4) userId : String - The userId that the player is using for authentication. In our SimpleUsers case this is the string of characters the the user types into the input textfield. In more advanced cases this can be Facebook UserID, Kongregate Id, OpenID Url, etc...

5) auth : String - This is the user's secret authentication token. In our case SimpleUsers casd this is the password entered into the password input textfield.

6) partnerId : * - String that identifies a possible affiliate partner. (Not used here
playerInsightSegments:* (Default = null)
segments for the user in PlayerInsight.

If this keyword is being used in the Document Class (sometimes called Main class or 1st Class) then it will indeed give a reference to the stage. 



Official API reference link:
PlayerIO.connect(
    stage,                                 
    "YOUR_GAME_ID",
    "public",                              
    "GuestUser",                           
    "",                             
    handleConnect,                         
    handleError                            
);   

private function handleConnect(client:PlayerIoClient):void {

}

private function handleConnect(error:PlayerIoClient):void {

}

  • Blog
  • About Jim
JimLynchCodes © 2021