GhostWire Studios :: Flash Components :: PHPObject



Forum Rules PHPObject

Please note that GhostWire Studios do not provide support for PHPObject. This is a peer-to-peer support area. Please try to help each other out to the best of your ability.

Thanks and enjoy!


Reply to this topicStart new topicStart Poll

> Multiple Methods in Actionscript
bjohnson
Posted: Feb 2 2006, 10:25 PM
Quote Post


Novice
*

Group: Members
Posts: 1
Member No.: 5065
Joined: 2-February 06



Hi;
I'm trying to expand on a working class I completed, but have run into a snag. I would like to have an initialization function that is called once when my program starts, but then access the phpobject for each additional function call. This class and calls work fine:
CODE

import com.ghostwire.phpobject.PHPObject;
import com.meychi.ascrypt.MD5;

class remote.SqlUser {
public static var userInfo;

public static var userName;
public static var fullName;
public static var email;
public static var resultFunc:Function;
public static var authenticated:Boolean = false;

public static function checkUser(user:String, pass:String, resultFunc:Function) {
 userInfo = new PHPObject("SqlUser");
 SqlUser.resultFunc = resultFunc;
 SqlUser.authenticated = false;

 userInfo.onError = function(code:Number, message:String):Void
 {
  // code 0: connection failure
  // code 1: server side error
  // code 2: client side error (currently happens only if method called does not exist in method list)
  switch (code) {
   case 1:
    message = "Server " + message;
    break;
   case 2:
    message = "Client " + message;
    break;    
  }
  TheTopSystem.app.log(code + ": " + message);
 }  

 userInfo.getUser_onResult = function(result)
 {
  if (result.length == 3) {
   trace(result[0] + ", " + result[1] + ", " + result[2]);
   SqlUser.userName = result[0];
   SqlUser.fullName = result[1];
   SqlUser.email = result[2];
   SqlUser.authenticated = true;
  }
  if (SqlUser.resultFunc != undefined)
   SqlUser.resultFunc(SqlUser.authenticated);  
 }  
 
 userInfo.getUser(user, MD5.calculate(pass));  
}

// From another location in the program this call works perfectly:
SqlUser.getUser(username, password);


But, when I try to use a separate initialization in order to init once, but have different function calls (getUser, registerUser...) it fails. Here's an example:
CODE

import com.ghostwire.phpobject.PHPObject;
import com.meychi.ascrypt.MD5;

class remote.SqlUser {
public static var userInfo;

public static var userName;
public static var fullName;
public static var email;
public static var resultFunc:Function;
public static var authenticated:Boolean = false;

public static function checkUser(user:String, pass:String, resultFunc:Function) {
 SqlUser.resultFunc = resultFunc;
 SqlUser.authenticated = false;
 userInfo.getUser(user, MD5.calculate(pass));    
}

public static function registerUser() {
 // What I hope to implement
}

public static function init() {
 userInfo = new PHPObject("SqlUser");

 userInfo.onError = function(code:Number, message:String):Void
 {
  // code 0: connection failure
  // code 1: server side error
  // code 2: client side error (currently happens only if method called does not exist in method list)
  switch (code) {
   case 1:
    message = "Server " + message;
    break;
   case 2:
    message = "Client " + message;
    break;    
  }
  TheTopSystem.app.log(code + ": " + message);
 }  

 userInfo.getUser_onResult = function(result)
 {
  if (result.length == 3) {
   trace(result[0] + ", " + result[1] + ", " + result[2]);
   SqlUser.userName = result[0];
   SqlUser.fullName = result[1];
   SqlUser.email = result[2];
   SqlUser.authenticated = true;
  }
  if (SqlUser.resultFunc != undefined)
   SqlUser.resultFunc(SqlUser.authenticated);  
 }    
}
}
// At program startup, I call SqlUser.init();
// Sometime later, I call SqlUser.getUser(username, password).
// Or, maybe I call SqlUser.registerUser();


This will fail with function not found getUser on the client side. Interestingly enough, if I call init() from within the getUser function it works fine. For example if I change the definition of getUser to the following, everthing works fine:
CODE

public static function checkUser(user:String, pass:String, resultFunc:Function) {
 SqlUser.init();
 SqlUser.resultFunc = resultFunc;
 SqlUser.authenticated = false;
 userInfo.getUser(user, MD5.calculate(pass));    
}


I'm using MTASC as my compiler. The question is: Do I have to re-create the PHPObject for everyfunction call? Or, am I going about this completly wrong? Basically, I would like to create the PHPObject("SqlUser") once, but then use the object for multiple function calls. Any help will be greatly appreciated.

Thanks
Brett
PM
Top

Reply to this topicStart new topicStart Poll