A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Undefined - High score table error

  1. #1
    Member
    Join Date
    Mar 2008
    Posts
    45

    Undefined - High score table error

    Hey guys,

    Ok basically I'v made my php file and my database (table). Now in flash I have made my high score table and have assigned instant names for all the dynamic text boxes. In the actionscript for flash I have used the follwoing code to let the dynamic text box know what field from my table it will be displaying:

    minimum1.text = Number_of_minimum_attempts;
    attempts1.text = Number_of_attempts;
    wrong1.text = Number_of_wrong_attempts;
    date1.text = Date_time;


    So for example minimum1 is the instance name and Number_of_minimum_attempts is my field name for my table.

    The problem I am getting is that when I run the flash file the high score table fields all say undefined. I have checked my php script to see for errors and my table.

    Any ideas guys?

    I have pasted the php code below incase it helps pick up the problem plus a jpg of the high score table.

    <?php

    $host = "localhost";
    $user = "root";
    $pass = "";
    $database = "activitysystem";
    $table = "activitytable";


    $dbcnx = @mysql_connect($host,$user, $pass);

    if (!$dbcnx) {
    echo( "<P>Unable to connect to the database server at this time.</P>" );
    exit();
    }

    if (! @mysql_select_db($database) ) {
    echo( "Unable to find database" );
    exit();
    }


    $result = mysql_query ("SELECT * FROM {$table} ORDER BY score DESC LIMIT 10");
    if (!$result) {
    echo("<P>Error performing query: mysql_error() </P>");
    exit();
    }

    for($x=0;$x <10;$x++)
    {
    $row = mysql_fetch_array($result);
    echo "ID : {$row["ID"]} <br>".
    "Number_of_minimum_attempts : {$row["Number_of_minimum_attempts"]} <br>".
    "Number_of_attempts : {$row["Number_of_attempts"]} <br>".
    "Number_of_wrong_attempts : {$row["Number_of_wrong_attempts"]} <br>".
    "Date_time : {$row["Date_time"]} <br><br>";
    }

    ?>
    Last edited by ish100; 04-15-2008 at 03:36 PM.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    get your php file to output -
    PHP Code:
    &Number_of_minimum_attempts=xxx&Number_of_attempts=xxx&Number_of_wrong_attempts=xxx&Date_time=xxx
    use a LoadVars object in Flash -
    PHP Code:
    lv = new LoadVars();
    lv.load("score.php");

    lv.onLoad = function(){
    trace(unescape(this)); // useful for debugging php errors
    minimum1.text lv.Number_of_minimum_attempts;
    attempts1.text lv.Number_of_attempts;
    wrong1.text lv.Number_of_wrong_attempts;
    date1.text lv.Date_time;
    }; 

  3. #3
    Member
    Join Date
    Mar 2008
    Posts
    45
    Hey,

    Thanks for your help,quick question does the xxx stand from my instance names of my dynamic text boxes?

    where do I add it to my php file, not sure how to add it aswell. I have attached my php file below:

    <?php


    $host = "localhost";
    $user = "root";
    $pass = "";
    $database = "activitysystem";
    $table = "activitytable";


    $dbcnx = @mysql_connect($host,$user, $pass);

    if (!$dbcnx) {
    echo( "<P>Unable to connect to the database server at this time.</P>" );
    exit();
    }


    if (! @mysql_select_db($database) ) {
    echo( "Unable to find database" );
    exit();
    }

    $result = mysql_query("SELECT * FROM {$table}");
    if (!$result) {
    echo("<P>Error performing query: mysql_error() </P>");
    exit();
    }


    for($x=0;$x <3;$x++)
    {
    $row = mysql_fetch_array($result);
    echo "ID : {$row["ID"]} <br>".
    "Number_of_minimum_attempts : {$row["Number_of_minimum_attempts"]} <br>".
    "Number_of_attempts : {$row["Number_of_attempts"]} <br>".
    "Number_of_wrong_attempts : {$row["Number_of_wrong_attempts"]} <br>".
    "Date_time : {$row["Date_time"]} <br><br>";
    }

    ?>

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    xxx refers to the numerical values returned from your php file

    what is the present output from your php file ?

    lv = new LoadVars();
    lv.load("score.php");

    lv.onLoad = function(){
    trace(unescape(this)); // shows php output, post the results here
    };

  5. #5
    Member
    Join Date
    Mar 2008
    Posts
    45
    Currently when I paste the code you gave:

    lv = new LoadVars();
    lv.load("new_msql.php");

    lv.onLoad = function(){
    trace(unescape(this)); // useful for debugging php errors
    minimum1.text = lv.Number_of_minimum_attempts;
    attempts1.text = lv.Number_of_attempts;
    wrong1.text = lv.Number_of_wrong_attempts;
    date1.text = lv.Date_time;
    };


    All i get on my table is undefined and a error report:

    <?php





    $host = "localhost";

    $user = "root";

    $pass = "";

    $database = "activitysystem";

    $table = "activitytable";





    $dbcnx = @mysql_connect($host,$user, $pass);



    if (!$dbcnx) {

    echo( "<P>Unable to connect to the database server at this time.</P>" );

    exit();

    }





    if (! @mysql_select_db($database) ) {

    echo( "Unable to find database" );

    exit();

    }



    $result = mysql_query("SELECT * FROM {$table}");

    if (!$result) {

    echo("<P>Error performing query: mysql_error() </P>");

    exit();

    }





    for($x=0;$x <10;$x )

    {

    $row = mysql_fetch_array($result);

    echo "name : {$row["name"]} <br>".

    "number_of_minimum_attempts : {$row["number_of_minimum_attempts"]} <br>".

    "number_of_attempts : {$row["number_of_attempts"]} <br>".

    "number_of_wrong_attempts : {$row["number_of_wrong_attempts"]} <br>".

    "date_time : {$row["date_time"]} <br><br>";

    }





    ?>&onLoad=[type Function]




    But I know my table name, database name, user name, host name is all correct because when I run the php file through my browser is get can see my data.

    I have attached my php file and a my flash document and a screen shot of my database if that helps.


    Thanks a million.
    Attached Images Attached Images
    Last edited by ish100; 04-15-2008 at 03:36 PM.

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Cannot open Flash 9 files here. Testing in Flash 8 with Wamp5 installed and running.
    new_msql.php in localhost folder - wamp/www

    in Flash, add all results to an associative array,
    pass zero to a function to display the first set of results -
    PHP Code:
    lv = new LoadVars();
    lv.load("http://localhost/new_msql.php");

    arr = [];

    lv.onLoad = function(){
    //trace(unescape(this));
    for(var n=0n!=lv.nRowsn++){
    obj = {};
    obj.Name lv['name'+n];
    obj.N0 lv['number_of_minimum_attempts'+n];
    obj.N1 lv['number_of_attempts'+n];
    obj.N2 lv['number_of_wrong_attempts'+n];
    obj.lv['date_time'+n];
    arr[n] = obj;
    }
    makeFields(0); // show first result
    }; 

    function 
    makeFields(num){
    trace(arr[num].Name)
    Name.text arr[num].Name;
    minimum1.text arr[num].N0;
    attempts1.text arr[num].N1;
    wrong1.text arr[num].N2;
    date1.text arr[num].D;

    make changes to php -
    PHP Code:
    <?php
     
      $host 
    "localhost"
      
    $user "root"
      
    $pass ""
      
    $database "activitysystem"
      
    $table "activitytable";  

      
    $dbcnx = @mysql_connect($host,$user$pass);
     
      if (!
    $dbcnx) {
        echo( 
    "<P>Unable to connect to the database server at this time.</P>" );
        exit();
      }
      
      if (! @
    mysql_select_db($database) ) {
        echo( 
    "Unable to find database" );
        exit();
      }
     
      
    $result mysql_query("SELECT * FROM $table");
      if (!
    $result) {
        echo(
    "<P>Error performing query: mysql_error() </P>");
        exit();
      }

    $nRows mysql_num_rows($result);
    echo 
    "&nRows=".$nRows."&";
     
      for(
    $x=0$x<$nRows;$x++){      
    $row mysql_fetch_array($result);
    echo 
    "name$x=".$row['name']."&".
    "number_of_minimum_attempts$x=".$row['number_of_minimum_attempts']."&".
    "number_of_attempts$x=".$row['number_of_attempts']."&".
    "number_of_wrong_attempts$x=".$row['number_of_wrong_attempts']."&".
    "date_time$x=".$row['date_time']."&";
     }
        
     
    ?>

  7. #7
    Member
    Join Date
    Mar 2008
    Posts
    45
    Thanks so much, you’re a genius. Really appreciate the help.

    Sorry got one more question; currently in my database table I have a few more entries. When I run the flash file is displays the first row of results in my table only.

    How do I alter the script telling it to display the second row of the table on dynamic text boxes:

    name2
    minimum2
    attempts2
    wrong2
    date2

    and so on for my third row of the table being (name3,minimum3,attempts3....etc)

    In total I have 10 rows of dynamic text boxes.



    Thanks so much

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    lv.onLoad = function(){ 
    numRows lv.nRows
    for(var 
    n=0n!=numRowsn++){ 
    obj = {}; 
    obj.Name lv['name'+n]; 
    obj.N0 lv['number_of_minimum_attempts'+n]; 
    obj.N1 lv['number_of_attempts'+n]; 
    obj.N2 lv['number_of_wrong_attempts'+n]; 
    obj.lv['date_time'+n]; 
    arr[n] = obj

    makeFields(numRows); // show all results 
    }; 

    function 
    makeFields(num){ 
    for(var 
    n=0;n!=num;n++){
    _root["name"+n].text arr[n].Name//name0.text, name1.text, name2.text..and so on
    _root["minimum"+n].text arr[n].N0
    _root["attempts"+n].text arr[n].N1
    _root["wrong"+n].text arr[n].N2
    _root["date"+n].text arr[n].D
    }; 
    hth

  9. #9
    Member
    Join Date
    Mar 2008
    Posts
    45
    Hey sorry to be a pain. I used the code you gave and im getting the following errors:

    **Error** Scene=Scene 1, layer=Action Script, frame=12:Line 15: Statement block must be terminated by '}'
    function makeFields(num){

    **Error** Scene=Scene 1, layer=Action Script, frame=12:Line 22: Syntax error.
    };

    Total ActionScript Errors: 2 Reported Errors: 2



    The code in place is:

    lv.onLoad = function(){
    numRows = lv.nRows;
    for(var n=0; n!=numRows; n++){
    obj = {};
    obj.Name = lv['name'+n];
    obj.N0 = lv['number_of_minimum_attempts'+n];
    obj.N1 = lv['number_of_attempts'+n];
    obj.N2 = lv['number_of_wrong_attempts'+n];
    obj.D = lv['date_time'+n];
    arr[n] = obj;
    }
    makeFields(numRows); // show all results
    };

    function makeFields(num){
    for(var n=0;n!=num;n++){
    _root["name"+n].text = arr[n].Name; name2.text, name3.text, name4.text, name5.text, name6.text, name7.text, name8.text, name9.text, name10.text
    _root["minimum"+n].text = arr[n].N0; minimum2.text, minimum3.text, minimum4.text, minimum5.text, minimum6.text, minimum7.text, minimum8.text, minimum9.text, minimum10.text
    _root["attempts"+n].text = arr[n].N1; attempts2.text, attempts3.text, attempts4.text, attempts5.text, attempts6.text, attempts7.text, attempts8.text, attempts9.text, attempts10.text
    _root["wrong"+n].text = arr[n].N2; wrong2.text, wrong3.text, wrong4.text, wrong5.text, wrong6.text, wrong7.text, wrong8.text, wrong9.text, wrong10.text
    _root["date"+n].text = arr[n].D; date2.text, date3.text, date4.text, date5.text, date6.text, date7.text, date8.text, date9.text, date10.text
    };


    Thanks for you'r help

  10. #10
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Code:
    function makeFields(num){ 
    for(var n=0;n!=num;n++){ 
    _root["name"+n].text = arr[n].Name; //name0.text, name1.text, name2.text..and so on 
    _root["minimum"+n].text = arr[n].N0; 
    _root["attempts"+n].text = arr[n].N1; 
    _root["wrong"+n].text = arr[n].N2; 
    _root["date"+n].text = arr[n].D; 
    };
    SHOULD BE
    Code:
    function makeFields(num){ 
    for(var n=0;n!=num;n++){ 
    _root["name"+n].text = arr[n].Name; //name0.text, name1.text, name2.text..and so on 
    _root["minimum"+n].text = arr[n].N0; 
    _root["attempts"+n].text = arr[n].N1; 
    _root["wrong"+n].text = arr[n].N2; 
    _root["date"+n].text = arr[n].D; 
    }
    }

  11. #11
    Member
    Join Date
    Mar 2008
    Posts
    45
    Hey thanks, fixed the syntax errors but im not recieveing anything from my database now. Endless problems....

    Iv attached my flash file and my php file if that helps.

    Thanks guys, course deadline this friday........getting close.
    Attached Files Attached Files

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