• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cannot pass variables from PHP to actionscript 3.0

Guest
Sep 24, 2011 Sep 24, 2011

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?

TOPICS
ActionScript

Views

2.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 24, 2011 Sep 24, 2011

Rewrite your PHP...

<?php

   echo "values=8";

?>

edited: removed info regarding different posting

Votes

Translate

Translate
LEGEND ,
Sep 24, 2011 Sep 24, 2011

Copy link to clipboard

Copied

Rewrite your PHP...

<?php

   echo "values=8";

?>

edited: removed info regarding different posting

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 24, 2011 Sep 24, 2011

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2011 Sep 24, 2011

Copy link to clipboard

Copied

Have you tried tracing e.target.data?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 24, 2011 Sep 24, 2011

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)  ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 24, 2011 Sep 24, 2011

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)  ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2011 Sep 24, 2011

Copy link to clipboard

Copied

As I showed earlier, remove the spaces around the = ...  "values=8"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 24, 2011 Sep 24, 2011

Copy link to clipboard

Copied

I get what you mean. Thanks for your help. This bug really drives me crazy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2011 Sep 24, 2011

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines