PDA

View Full Version : [AS3] send Object DataType, flash->PHP (simple Q)


watcher
12-16-2006, 09:11 PM
Hi people,

simple question
How can i get the property values from an Object datatype in PHP?

situation: AS3.0 example
Using AS3.0 i am sending to PHP two variables inside an Object like this:

var var1:int = Math.floor( Math.random( ) * 100 );
var var2:String = "test string";
var test:Object = new Object();
test.var1 = var1;
test.var2 = var2;

var request:URLRequest = new URLRequest( "path_to_php_file" );
request.data = test;
request.method = URLRequestMethod.POST;

var loader:URLLoader = new URLLoader( );
loader.addEventListener( Event.COMPLETE, handleResponse );
loader.load( request );
situation: PHP example
path_to_php_file points to PHP file called from flash, its content looks like this:

<?php
$glob = $GLOBALS['HTTP_RAW_POST_DATA'];
$fgc = file_get_contents("php://input");

echo "GLOBALS:__" . $glob .
"\nfile_get_contents:__" . $fgc .
"\nPOST:__" . $_POST;
?>
The result is traced in flash (function handleResponse ), and it traces:

GLOBALS:__
file_get_contents:__[object Object]
POST:__Array
i also tried.. (not working)
echo $fgc->var1 // returns empty string
echo $fgc['var1'] // returns left bracket --> [ (lol..)
echo $_POST[0] // returns empty string

my questions
1. GLOBALS: why does $GLOBALS['HTTP_RAW_POST_DATA'] return empty string?
2. file_get_contents: how can i trace values of properties var1 and var2 inside PHP?
3. POST: how can i trace values of that Array datatype inside PHP ?

You see, this is simple problem, and i am complete llama (http://en.wikipedia.org/wiki/Llama)with PHP :)
Thank You so much for Your time..

watcher
12-17-2006, 09:55 AM
wow, nobody so far really knew the answer?

I thought this would be a simple question.. no matter then, the same kind-of-a-question could be "how would You send 2 different variables of two different types from AS3.0 to PHP and parse them correctly in PHP" (without using additional container in flash to store them)?

Although i still believe somebody knows the answers to prev questions (some of them at least?) :)

thank You!

senocular
12-17-2006, 11:17 AM
You dont. You have to send them separately.

watcher
12-17-2006, 01:32 PM
You dont. You have to send them separately.
Can You please post an example/link of how to send these variables separately?


--- few more findings ---------------------------------------------
I just recently tried using an Array (with 2 variables) instead of Object, and MovieClip (with 2 local vars) instead of Object (ala AS2.0).

here is what the PHP traced:

// using Array (see original php source above using Object)
// in flash:
var test2:Array = new Array("some string", 1);
request.data = test2;

// in PHP:
echo "\n\n\n\n\nGLOBALS:__" . $glob . // GLOBALS:__
"\nfile_get_contents:__" . $fgc. // file_get_contents:__some string,1
"\nPOST:__" . $_POST; // POST:__Array

// certainly $fgc returns something interresting here, however:
echo "file_get_contents:__" . $fgc[0]; // returns: file_get_contents:__s (which is the first letter of "some string" String), PHP puts each character separately into itso own array index, meaning:
$fgc[0] == "s";
$fgc[1] == "o";
$fgc[2] == "m";
$fgc[3] == "e";
....

.. this would be passable for me, meaning these characters
could be concatenated and the intitial flash variables
re-created, but values of these variables would have to NOT
use comma: , character as delimiter, and that's not passable
for my purposes [i use comma quite often in variables
passed to PHP]

// using MovieClip (see original php source above using Object)
// in flash:
var testMc:MovieClip = new MovieClip();
testMc.var1 = "bla";
testMc.var2 = "test string 2";
...
request.data = testMc;

// in PHP:
echo "\n\n\n\n\nGLOBALS:__" . $glob . // returns: GLOBALS:__
"\nfile_get_contents:__" . $fgc. // returns: file_get_contents:__[object MovieClip]
"\nPOST:__" . $_POST; // returns: POST:__Array

// certainly $fgc (again) returns something interresting here, however:
echo "file_get_contents:__" . $fgc['var2']; // returns: file_get_contents:__[ (again this bracket [?!])

senocular
12-17-2006, 05:41 PM
sorry, I jumped the gun there a little (in a hurry and I dont like reading, I know :crazy: ) At first glance I thought you were doing a data.test = test, where you already had data setup and were giving it a complex varible. Looking back I think you're just missing the URLVariables instance used for data. Since you're defining them in test now, you should just be able to make test an instance of URLVariables instead of a generic object. See if that works.

PeakStudios
04-23-2008, 06:45 PM
Try Peak Studios Flash PHP MySQL Extension (http://peakstudios.com/actionscript-3-flash-php-mysql-pannel-extension). They have video tutorials showing you how easy the plug-in is to use and it will write most of your code for you.


Hope this helps!
Quince