Copy link to clipboard
Copied
I am using CS3 and I write the following code as to pass variable to flash from PHP
Actionscript
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
var myRequest:URLRequest=new URLRequest("http://localhost/moodle/value.php");
myLoader.load(myRequest);
myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
var myValue: String;
function onCompleteHandler(e:Event):void{
var myvariable: URLVariables = new URLVariables(e.target.data);
myValue = myvariable.values;
trace(myValue);
}
PHP file
<?php
echo ('values = 8');
?>
But I always get the error and cannot get the values by using trace();
Before i try to use "myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;" I still get the same error.
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
Can anyone help me?
Rewrite your PHP...
<?php
echo "values=8";
?>
edited: removed info regarding different posting
Copy link to clipboard
Copied
Rewrite your PHP...
<?php
echo "values=8";
?>
edited: removed info regarding different posting
Copy link to clipboard
Copied
The error is fixed.The new version is like that
Actionscript
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
var myRequest:URLRequest=new URLRequest("http://localhost/moodle/value.php");
myLoader.load(myRequest);
myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
var myValue: String;
function onCompleteHandler(e:Event):void{
var myvariable: URLVariables = new URLVariables(e.target.data);
myValue = myvariable.values;
trace(myValue);
}
php file
<?php
echo "values=8";
?>
The output finally is "null" in flash file. Why does it happen? It should give me 8 when I input trace(myValue);
Copy link to clipboard
Copied
Have you tried tracing e.target.data?
Copy link to clipboard
Copied
I get "values = 8" after i do it
function onCompleteHandler(e:Event):void{
var myvariable: URLVariables = new URLVariables(e.target.data);
trace(e.target.data);
}
Thank you! But if I want to pass 2 php variables, one is $d, one is $r, say, for example
<?php
$d = "How are you";
$e = 4;
echo $d&$e;
?>
How can I get the 2 variables from php if I use it in this way in actionscript? Is that trace(e.target.data.d) and trace(e.target.data.r) ?
Copy link to clipboard
Copied
I get "values = 8" after i do it
function onCompleteHandler(e:Event):void{
var myvariable: URLVariables = new URLVariables(e.target.data);
trace(e.target.data);
}
Thank you! But if I want to pass 2 php variables, one is $d, one is $r, say, for example
<?php
$d = "How are you";
$e = 4;
echo $d&$e;
?>
How can I get the 2 variables from php if I use it in this way in actionscript? Is that trace(e.target.data.d) and trace(e.target.data.r) ?
Copy link to clipboard
Copied
As I showed earlier, remove the spaces around the = ... "values=8"
Copy link to clipboard
Copied
I get what you mean. Thanks for your help. This bug really drives me crazy.
Copy link to clipboard
Copied
You're welcome