The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 5 of 5

Thread: Passing variables to Actionscript from Php

  1. #1

    Passing variables to Actionscript from Php

    I know next to nothing of php, and was given a file that does a few calculations and such, then shows a Flash movie and is supposed to pass the variables to the flash movie. The problem is that when the variables load in flash they look like this "condition=1,1" instead of how they are supposed to look "condition=1." I am not sure if the problem lies in the php script, the actionscript, or somewhere in between. All the tutorials that I can find inform me as to how to load variables from a php script into flash, but dont help much with the writing of the php script. Can someone look through the code and tell me if everything looks correct, and maybe help me understand what is actually going on. What is confusing me most is that I cannot find any code that outputs the variables.
    Here is the Php (comments were written by my collaborator to help me understand it)
    PHP Code:
    $numofconditions 6;  
    $conditionfilename "$experimentname.txt"
    //here is where we assign condition:
    //read file
    $condition_fh file($conditionfilename); //this opens the condition file to figure out what the last conditon run was
    $count count($condition_fh)-1//this counts the number of rows in the condition file
    $lastcondition $condition_fh[$count]; //this sets $lastcondition to the last number in the file...the last condition that was run
    //print "$conditionfilename - $count - $lastcondition<br>";    
    if($lastcondition ==$numofconditions){$newcondition 1;} else {$newcondition $lastcondition +1;} //this tells the program to go to the next condition. Also it sets it back to condition 1 if the last condition was equal to $numofconditions
    $fh fopen($conditionfilename'a'); //this opens the condition file to write the new conditon in
    fwrite($fh,"$newcondition\n"); //this writes the new condition to the file
    fclose($fh); //closes the file
    //Often times you want to know if someone started your experiment and then quit before submitting the data. 
    //The next bit of code creates another file for you which simply keeps a log of IP address of anyone who started the program and when they did so
    $date_start date("Y-m-d"); //gets the current date
    $time_start date("H:i:s"); //gets the current time
    $fh =fopen("startlog.csv"'a'); //opens or creates a file called "startlog.csv" 
    $ip $_SERVER['REMOTE_ADDR']; ///gets the IP address of the user
    fwrite($fh,  "$ip,$newcondition,$date_start,$time_start\n"); //writes, the IP, condition, date, and time for every person that launches this program
    fclose($fh); //closes the file
    $filename="$experimentname.php"//defines the name of the file being run as the name of the experiment
    $flashfile="$experimentname.swf"//defines the name of the flash program as the name of the experiment
    $bgcolor "#ffffff"//sets the background color of the flash program
    $width "800"//sets the width of the flash program
    $height "600"//sets the height of the flash program
    //The next two lines defines all the variables to pass to flash.
    $valuestopass "ip=$ip&experimenttitle=$name&experimentname=$experimentname&filename=$filename&condition=$condition&date_start=$date_start&time_start=$time_start";
    $sendline $flashfile "?" $valuestopass;
    //The next line outputs the flash file to the user   
    print "<table width='100%' height='100%' cellpadding='0' cellspacing='0' bgcolor='#ffffff'>
    <td><div align='center'>
    <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase=',0,0,0' width='800' height='600' id='preloader' align='middle'>
    <param name='allowScriptAccess' value='sameDomain' />
    <param name='movie' value='
    $sendline' />
    <param name='quality' value='high' />
    <param name='bgcolor' value='
    $bgcolor' />
    <embed src='
    $sendline' quality='high' bgcolor='$bgcolor' width='$width' height='$height' name='$name' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='' />    
    here is my variable loader in AS3 if whoever reads this happens to know both
    var condition
    function dataLoader() {
     var request:URLRequest=new URLRequest("insert url here");
     var loader:URLLoader = new URLLoader();
     loader.addEventListener(Event.COMPLETE, completeHandler);
     function completeHandler(evt:Event) {
      trace('IP = ' + ip);
      trace('Experiment Name = ' + experimentname);
      trace("Condition = "+condition);
      trace("Start Date = "+date_start);
      trace("Start Time = "+time_start);

  2. #2
    Comment all these lines
    //The next line outputs the flash file to the user   
    print "<table width='100%' height='100%' cellpadding='0' cellspacing='0' bgcolor='#ffffff'>
    <td><div align='center'>
    <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase=',0,0,0' width='800' height='600' id='preloader' align='middle'>
    <param name='allowScriptAccess' value='sameDomain' />
    <param name='movie' value='$sendline' />
    <param name='quality' value='high' />
    <param name='bgcolor' value='$bgcolor' />
    <embed src='$sendline' quality='high' bgcolor='$bgcolor' width='$width' height='$height' name='$name' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='' />    
    and put this

     echo $valuestopass;

    See what is happening in the variable output.

  3. #3
    Thank you for the response. That would work, but that page is the page the flash movie loads in. If i comment out those lines then the movie wont show anywhere. I suppose the fix would be load the movie on a different page.
    I actually fixed the problem a different way. I was so ignorant to anything programming that i had no idea what a query string variable was, and didnt know that that was how the variables were being passed in the AS2 version. I guess in AS 2 you didnt have to do any work when this is done, you can use them as if they were already declared. In AS3 i removed the dataLoader function and just assigned the variables like this
    var condition:int=int(LoaderInfo(this.root.loaderInfo).parameters.condition)
    and so on for each variable
    dunno if this helps you at all, but i included it in case someone else comes along with the same question

  4. #4
    icio's Avatar
    looks better in lowercase
    If you look on the main page of the website there is a tutorial detailing how to set up your HTML to pass the details into flash. I suggest you look there.
    "60% of the time it works... every time." -- Paul Rudd as Brian Fantana.

  5. #5
    You assigned the variable condition once again after the event load complete. There is no need for that if you send variables using the javascript into flash.
    And to receive variables you have to declare like that.
    I doubt how the ',' is there in the condition.
    Anyway it is solved.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012