We help IT Professionals succeed at work.
Get Started

Loading in variables from php script flash as3

Alex500 asked
Last Modified: 2013-11-11
Hey, Im working on a script that loads variables from a php page into a flash document and I cant seem to get it to work. Eventually i will need the figure  as a variable so i can pass it to movieclips that will animate.

my flash as3 code is as follows

package {
      import flash.display.Sprite;
    import flash.events.MouseEvent;
      import flash.events.*;
      import flash.display.*;
      import flash.net.URLRequest;
      import flash.display.Loader;
      import flash.events.ProgressEvent;
      import flash.net.URLVariables;
      import flash.net.URLLoader;
      import flash.net.URLRequestMethod;
      import flash.net.URLLoaderDataFormat;
      import flash.net.URLRequest;
      import flash.net.navigateToURL;
      public class quizResults extends MovieClip {
                        private var england:englandText_mc = new englandText_mc();
                        private var theRecord:String;
                        private var loadData:URLLoader = new URLLoader();
                  public function quizResults() {
                              england.x = 200;
                              england.y = 200;
                  function getData() {
                        //theRecord = loadthis.text;
                        var variables:URLVariables = new URLVariables();
                        var varSend:URLRequest = new URLRequest("http://localhost:8888/FlashDev/facebook-version/new/Quiz/loadScore.php");
                        varSend.method = URLRequestMethod.POST;
                        varSend.data = variables;
                        var varLoader:URLLoader = new URLLoader;
                        varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
                        varLoader.addEventListener(Event.COMPLETE, showResults);
                  function showResults (event:Event): void {
                        if (event.target.data.msg == "Ok") {
                              england.text = event.target.data.englandVar;
                              trace("YES ALEX YOU WIN!");
                        }      else {
                              trace("ALEX YOU FAIL AT LIFE");

and this is my php script:

$englandQuery = mysql_query("SELECT * FROM main WHERE country ='England'");

$gamesPlayedEngland = 0;
$totalScoreEngland = 0;

while ($england = mysql_fetch_array($englandQuery)) {
                  $totalScoreEngland += $england['score'];      

            echo "Average Score " ;
            echo $totalScoreEngland/$gamesPlayedEngland;
            $resultEngland = $totalScoreEngland/$gamesPlayedEngland;
            $englandVar = $resultEngland;
            echo "<br />";
            echo "<br />";
            if ($englandVar != 0) {
                  $output .= "msg=Ok";
                  $output .= "&score=" . $englandVar;      
                  echo $englandVar;
            } else {
                  $output = "msg=Error";
            echo $output;

the php works fine as i have tested this and i dont get any errors in my script when i compile the swf. however when i load the swf i get my "alex you fail at life" message and i cant work out why.


Watch Question
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE