Retreiving Data in AS3.0 passed by amfphp2.0
Hi, I have worked out my amfphp service that makes a simple database request of all columns in a table and I verified my services in the amfphp service browser and it works fine.
But I'm having a hard time accessing my data once I catch it in AS3.0 as an Object or as an Array. I've used the PizzaService that ships with amfphp2.0 as an example and I am able to catch the string 'magarita' from the service but I am unable to retrieve my data from any other datatype. I've tried to access .serverInfo.initialData as he does in the video tutorial part 2 on amfphp in the site of amfphp but I am unable to access that data, it is undefined.
I understand that the returned set from mysql throught amfphp don't seem to be directly accessible to AS3.0 just as I would access a string from php.
Can someone help me understand how I am to capture the data coming from objects or arrays of mysql coming throught amfphp2.0 ?
thank you
--
I've just found out how to properly access my array made in php from a mysql statement. Obvious to those who knows but this if of course for those who don't know.
I use this php code as my service
public function Logintest2( $username, $password, $acctype )
{
$req = mysql_query("SELECT username, password, account_type FROM users WHERE username='$username' AND password='$password' AND account_type='$acctype'") or die(mysql_error());
$ret = array();
while ($data = mysql_fetch_object($req))
{
$ret[] = $data;
}
return $ret;
}
and here is what I used in AS3.0
function onComplete(result:Array):void
{
if (result[0].username)
{
trace("Success !");
trace("");
trace("User " + result[0].username + " with a password of " + result[0].password + " as an account type of " + result[0].account_type);
trace("has successfuly loged in");
}
else
{
trace("User login failed");
}
}
this way I was able to retrieve my data using result[0].username, I guess I've tried all the wrong ways of doing this before doing it right, well for me that is. But my code isn't perfect as of right now, the else don't serve any purpose, when I have a wrong login, I get an undefined property wich I suspect to be my way of doing it wrong trying to see with my IF statement if the .username exist or is TRUE on result[0], how else could I try to detect if I did received something or not ? hmm maybe with a TRY statement ? I dunno, but I'l go back working at it.
I thought this might help Jake2641 to understand how you could retrieve your data. I used a while loop to populate a php array and returned that array. In AS3.0 I catch it as an array throught the function my responder has and access it [0].username this way. I've got the undefined plenty of times before, althought I can't tell you exactly what it is, I suspect it to simply be the way you are trying to access your data is incorrect in its syntax just like me puting a IF (result[0].username) {Do this...} but if it is not there, it seems to trow an error of type TypeError: Error #1010. But I am no pro, just trying to help from what I know and I know very little, hope this help in any way. Later.
Last edited by Sandcode; 07-01-2012 at 03:58 AM.
Reason: To clarify
|