mercredi 21 septembre 2016

Flash Database Operation Failed

I have a problem with my Flash (.fla) project. I've connected my flash with database with php script. I used ActionScript 2.0.

The problem is data can show at compile program on AdobeFlash CS6 (CTRL+Enter) but data cant show in datagrid when I open the .swf.

It's my php script

<?php

mysql_pconnect ("localhost", "root", "");
mysql_select_db ("modul");


   $qr = mysql_query("SELECT * from nilaisiswa");
   if (!qr || mysql_num_rows($qr)==0) {
      $r_string = '&errorcode=3&msg='.mysql_error().'&';
   } else {
      $r_string = '&errorcode=0&n='.mysql_num_rows ($qr);
      $i = 0;
      while ($row = mysql_fetch_assoc ($qr)) {
         while (list ($key, $val) = each ($row)) {
            $r_string .= '&' . $key . $i . '=' . stripslashes($val);
         }
         $i++;
      }

      $r_string .='&';
   }

echo $r_string;
?>

And here it's my ActionScript 2.0

var select_lv:LoadVars = new LoadVars();
var insert_lv:LoadVars = new LoadVars();
var delete_lv:LoadVars = new LoadVars();
var today:Date = new Date();
var deleteIndex:Number;

var errorMsgs:Array = [
    "",     
    "Couldn't connect to server",
    "Couldn't connect to database",
    "Error running query",
    "First four entries may not be deleted"];

var filepath:String;

var scoreInfo:Array = [];

var headerListener:Object = {};
headerListener.headerRelease = function(event:Object) {
    switch (event.columnIndex) {
        case 0:
            if (scores_dg.getColumnAt(0).sortedUp) {
                scores_dg.sortItemsBy(scores_dg.columnNames[0], Array.CASEINSENSITIVE | Array.DESCENDING);
            } else {
                scores_dg.sortItemsBy(scores_dg.columnNames[0], Array.CASEINSENSITIVE);
            }
            scores_dg.getColumnAt(0).sortedUp = !scores_dg.getColumnAt(0).sortedUp;
            break;
        case 1:
            if (scores_dg.getColumnAt(1).sortedUp) {
                scores_dg.sortItemsBy(scores_dg.columnNames[1], Array.NUMERIC | Array.DESCENDING);
            } else {
                scores_dg.sortItemsBy(scores_dg.columnNames[1], Array.NUMERIC);
            }
            scores_dg.getColumnAt(1).sortedUp = !scores_dg.getColumnAt(1).sortedUp;
            break;
    }
}

function zerofill(n:Number):String {
    if (n<10) return '0' + n.toString();
    else return n.toString();
}

filepath = "http://localhost/tesis/";

nickname_ti.maxChars = 50;
date_ti.maxChars = 10;
score_ti.text = 0;
date_ti.text = today.getDate() + '-' + zerofill(today.getMonth()+1) + '-' + zerofill(today.getFullYear());


select_lv.onLoad = function(ok:Boolean) {
    if (ok) {
        if (this.errorcode=="0") {
            for (var i:Number=0; i < this.n; i++) {
                scoreInfo.push(
                    {record:this["id"+i],
                     nickname:this["nickname"+i],
                     score:Number(this["score"+i]),
                     dateposted:this["dateposted"+i]
                    });
            }
            scores_dg.columnNames = ["nickname", "score", "dateposted"];
            scores_dg.getColumnAt(0).width = 130;
            scores_dg.getColumnAt(0).sortOnHeaderRelease = false;
            scores_dg.getColumnAt(0).sortedUp = false;
            scores_dg.getColumnAt(0).headerText = "Nickname";
            scores_dg.getColumnAt(1).width = 130;
            scores_dg.getColumnAt(1).sortOnHeaderRelease = false;
            scores_dg.getColumnAt(1).sortedUp = false;
            scores_dg.getColumnAt(1).headerText = "Score";
            scores_dg.getColumnAt(2).width = 130;
            scores_dg.getColumnAt(2).headerText = "Date Posted";
            scores_dg.dataProvider = scoreInfo;
            scores_dg.addEventListener("headerRelease", headerListener);
            msg_ta.text = "Enter data and click Add to add a score.";
        } else {
            msg_ta.text = errorMsgs[Number(this.errorcode)];
            if (this.errorcode == "3") msg_ta.text += ": " + this.msg;
        }
    } else {
        msg_ta.text = "Flash-database select operation failed";
    }
}
msg_ta.text = "Getting high scores from database...";
select_lv.sendAndLoad(filepath + "getscores.php", select_lv, "GET");

Aucun commentaire:

Enregistrer un commentaire