1

I'm trying to send multiple values from PHP to Flash. I know how to send back one value, and that's by using PHP's print or echo, and then in flash using e.target.data., for example...

PHP:

print "resultMessage=$something";

Flash:

var resultText:TextField;
resultText.text = e.target.data.resultMessage;

The problem is when trying to receive 2 values; I've tried things like...

PHP:

print "resultNumber=$somethingNumber";
print "resultName=$somethingName";

Flash:

var flashNumber:TextField
flashNumber.text = e.target.data.resultNumber;
var flashName:TextField;
flashName.text = e.target.data.resultName;

But when I try that, flashNumber would end up as flashNumber and flashName mashed together, like 2Tom or 7Mary or something like that. I tried printing <br> between the 2 values in PHP, but I still got the same result. I know that I can split the PHP into 2 PHP files and get a value from each one, but that would be a little ridiculous, since in my program I'll need to get many values.

Is there another way to send values from PHP to Flash, so that I can send more than 1 value? Or, is there a way to use print or echo to send more than 1 value?

Thank you very much in advance.

2 Answers 2

1

You can do this by outputting your data in a standard URL encoded variable format. (You need the ampersand that applications use to separate variables - otherwise it thinks everything after the first = is the value)

eg: print "resultNumber=$somethingNumber&resultName=$somethingName";

Then AS3 should automatically work the way you are trying.


You could also ouput XML or JSON as suggested by someone else.

JSON

PHP

<?php
$arr = array(somethingName, somethingNumber);

echo json_encode($arr);
?>

AS3

var jsonObj = JSON.parse(e.target.data);
trace(jsonObj.somethingName, jsonObj.somethingNumber);

XML

PHP

<?php
$string = <<<XML
<data>
 <somethingName>
  blah blah blah
 </somethingName>
 <somethingNumber>
  12345
 </somethingNumber>
</data>
XML;

$xml = new SimpleXMLElement($string);

echo $xml->asXML();

?>

AS3

myXML = new XML(e.target.data);
trace(myXML.somethingName, myXML.somethingNumber);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot for your help, I thought using an ampersand would throw me an error like using a comma did...I'll also keep the JSON and XML methods in mind in case. Thanks again.
0

Better use some data formatting instead of passing data as pure text - XML or JSON is a good idea.

1 Comment

Please consider updating your answer to be more useful. As it is it's more of a comment and doesn't actually show how do anything

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.