A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Flash to PHP problem

  1. #1
    Junior Member
    Join Date
    Apr 2006
    Posts
    8

    Flash to PHP problem

    this must be super simple, but I have wasted hours and cant figure out why it wont work.

    I load data mysql database, that works great.

    PHP Code:

    $result 
    mysql_query("select * from diploma order by id desc limit 2") or die ("could not read news database");
        if (
    $result)
        {
        while (
    $row mysql_fetch_array($result))
        {
           
     
            print 
    $row["text"];
            print 
    "<br>";
            
            
    $mail =  $row["text"];
            

            
    $vars $mail 

    echo 
    "&returnVal=$vars"
       
              }
        } 
    the php part works.

    now in flash I create a dynamic textfield and give it an instance name "text"

    then I attach this code

    PHP Code:
    myVars = new LoadVars();
    // call the load method to load my php page
    myVars.load("source.php");

    myVars.ref this

    // once vars have been loaded, we will have these variables:

    myVars.onLoad = function(succes){ 
    if(
    succes){
        
    output.text =  myVars.returnVal;

                    }
                
         else 
    trace("Error loading data") } 
    now the text SHOULD show up in the textfield but it doesnt. what is wrong?

    thanks

  2. #2
    Junior Member
    Join Date
    Sep 2007
    Posts
    23
    hmm
    This is what I've used before when learning it from Kirupa

    PHP: (varload.php)
    PHP Code:
    <?php
    //These variables will store stuff from 
    //your database using sql query
    $php1 "Output1";
    $php2 "Output2";
    $php3 "Output3";

    /*
    add those variables to $var variable 
    using & so flash can read them 
    fla1,2,3 is the variable name used in flash
    */
    $var "&";
    $var .= "fla1=" $php1 "&"
    $var .= "fla2=" $php2 "&"
    $var .= "fla3=" $php3
    echo 
    $var;
    ?>
    Flash: (var.fla 3 text dynamic texts to store 3 fla variables fields)
    PHP Code:
    myVars = new LoadVars(); 
    myVars.onLoad=function(success){
    if(
    success){
    //Converting from the php to flash variable to dynamic text
    fla1.text this.fla1// "Output1"
    fla2.text this.fla2// "Output2"
    fla3.text this.fla3// "Output3"
    err.text "Variables Successfully Loaded."
    } else {
    err.text "Error Loading Variables...";
        }
    }
    //load page containing vars
    myVars.load("http://domain.com/varload.php"); 
    I'm not completely sure what the problem would be
    but have you tried changing
    echo "&returnVal=$vars";
    to
    echo "&returnVal=" . $vars;

    and from what I gather
    echo "&returnVal=$vars";
    is going to be printing
    text
    text
    text

    as 1 string? (I'm not quite sure flash likes HTML like <br> while converting to flash)
    Last edited by lp9sc; 03-27-2010 at 03:12 AM.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center