Forum BigDB client.bigdb how do i reach client?

Discussion and help relating to the PlayerIO database solution, BigDB.

client.bigdb how do i reach client?

Postby adahy » September 19th, 2015, 6:07 pm

noob alert..

i am trying to connect to bigdb. I use client.bigdb.loadmyplayerobject() but what/where exactly is the client?

in my actionscript, i can only use this connect code in the private function handleconnect(client:Client) function because it already has client there.

How can i use or reference client in other places in my code so I can make this call to bigdb wherever i'd like and not be forced to only do it in the handleconnect(client:Client) function?

I am a noob, sorry for my lame question m(_ _)m thank you!

trying to make something like this work?
Code: Select all
private function loadObjects():void{
         
         client.bigDB.loadMyPlayerObject(function(obj:DatabaseObject):void{
                   obj.Level = 8; //Modify object
               obj.Name = myPlayer.nameThing;
               obj.save(); //Save changes
         });
}
adahy
 
Posts: 16
Joined: April 13th, 2010, 9:14 am

Re: client.bigdb how do i reach client?

Postby adahy » September 19th, 2015, 6:16 pm

I dont think this is the proper way to do this but it seems to be working...

i declare a new variable at the beginning of the class: private var clientswf;

then, in the private function handleConnect(client:Client):void{ } function i use

clientswf=client;



now I am able to reference the client wherever in my code via clientswf.


This isnt the proper way to do this is it? How should I be referencing the client? Thank you!!!!
adahy
 
Posts: 16
Joined: April 13th, 2010, 9:14 am

Re: client.bigdb how do i reach client?

Postby Guillaume » September 19th, 2015, 6:43 pm

Just reference it on a variable that is globally accessible in your program.
Your client object is an authenticated user. So just keep it somewhere in memory, when you need to do some operations on any service.
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: client.bigdb how do i reach client?

Postby adahy » September 20th, 2015, 5:12 am

Guillaume wrote:Just reference it on a variable that is globally accessible in your program.
Your client object is an authenticated user. So just keep it somewhere in memory, when you need to do some operations on any service.


thank you. do I make the reference in: private function handleConnect(client:Client):void{} function?
public var clientswf:Client;
clientswf=client;

then use clientswf everywhere when referencing client?
adahy
 
Posts: 16
Joined: April 13th, 2010, 9:14 am

Re: client.bigdb how do i reach client?

Postby Guillaume » September 20th, 2015, 12:50 pm

If your variable is globally accessible then yes. It depend the structure of your code.

When working in C#, i have some static class, where i can stock static variable, like Client, in order to access it from everywhere, any file and any context.

Something like:

Code: Select all
public static class MyStaticClass
{
     private static Client client;

     public static void GetClient(Callback onClient, Callback<PlayerIOError> onError)
     {
          if (client == null)
          {
             //Do something to get the client, like authenticate
             //Some code...Then setting client object to my static object
             var myClient = PlayerIO.Authenticate("something...");
             client = myClient;
            //If something bad hapenned, returning onError with the error context
             if (someError)
               onError(myErrorObject);
          }
          //If i'm here, i authenticated, or using previously authenticated object
          //Calling success callback in order to continue my code workflow
          onClient(client);
     }
}


You have to adapt this exemple to AS3. But with this in mind you only have to call:

Code: Select all
MyStaticClass.GetClient(delegate(Client client) {
    //Doing your code workflow here
}, delegate(PlayerIOError error) {
   //Managing the case when your client was unable to be retrieved here
});


In AS3 it would be something like:

Code: Select all
MyStaticClass.GetClient(function (client:Client): void {
    //Doing your code workflow here
}, function (error:PlayerIOError): void {
   //Managing the case when your client was unable to be retrieved here
});
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France


Return to BigDB



cron