Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Supporting Technologies > Flash Remoting

Reply
 
Thread Tools Rate Thread Display Modes
Old 01-27-2011, 04:35 AM   #1
Jake2641
Senior Member
 
Jake2641's Avatar
 
Join Date: Jul 2008
Posts: 149
Default [AS3] Pass PHP array to flash via AMFPhp

The title says it all.
The php side:
What is going into PHP is a string that contains this:
"i1&i2&i3&
PHP Code:
function createArray($SQLArray)
    {
        
$newArray explode("&"$SQLArray);
        
//Slices off the unused array element from the extra &
        
$newArray array_slice($newArray0, (count($newArray) - 1));
        return 
$newArray;
    } 
what gets send out in the AMF browser is a php array of i1 i2 and i3 all nice and perfect.
I have checked the variable and userEquipment_DB does indeed contain "i1&i2&i3&"
ActionScript Code:
var userEquipment:Array = new Array; userEquipment = gw.call("SetArray.createArray", setUpdateRes, userEquipment_DB);

whats happening (and i did a trace on the gw.call) is that its comming back undefined:
1067: Implicit coercion of a value of type void to an unrelated type Array.
I know that the php is not the problem and its sending back an array.

Any ideas?
Jake2641 is offline   Reply With Quote
Old 01-27-2011, 05:25 AM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 9,789
Send a message via Skype™ to henke37
Default

May I ask how that you know that the php code isn't the problem? Did you verify the http reply body by hand?
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 01-27-2011, 04:24 PM   #3
Jake2641
Senior Member
 
Jake2641's Avatar
 
Join Date: Jul 2008
Posts: 149
Default

I used the AMFPhp browser to check my php scripts and in the browser I set the $SQLArray variable to i1&i2&i3& and it returned an array just fine.
Jake2641 is offline   Reply With Quote
Old 07-01-2012, 02:01 AM   #4
Sandcode
Registered User
 
Join Date: Dec 2010
Posts: 8
Default 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
Sandcode is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:40 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.