lundi 17 avril 2017

Subarrays disappearing in Amfphp, Actionscript 3 data integration

I recently upgraded to php 5.6 and amfphp 2.2.2 and I'm trying to modify the way the data is handled in an Actionscipt 3 animation that I wrote several years ago (I haven't worked with AS3 for a long time so that may well be part of the problem here).

The amfphp site (Silex Labs) says to simply use PDO for your data and AS3 and amfphp will handle it properly, but that's not working.

The AS3 "Responder" class handles the incoming data from amfphp and it no longer uses "responds.serverInfo.initialData". So AS3 can no longer process the data the way it did with amfphp 1.9.

So I wrote a script to parse the data. I apparently don't understand the structure of the data object that amfphp provides to the AS3, but I was able to extract the data from the object and store in an array.

I can trace the data in the triple loop in the AS3 script, but outside of the loop the subarrays are undefined.

I must be doing something wrong in the AS3. Can anyone see what it is?

The php:

<?php
function getConnection() {
    return new PDO('mysql:host=localhost;dbname=db-name', 'root', '',
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}

function getData() {
    $pdo = getConnection();
    $tsql = "SELECT col0, col1, col2, col3, col4, col5, col6, col7 
           FROM somedata ORDER BY index_num ASC"; 

    $stmt = $pdo->prepare($tsql);
    $stmt->execute();
    $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
    return $results;
}

?>

The AS3:

        public class GetSomeData extends Sprite {
    private var gw:NetConnection = new NetConnection();
    private var getRes:Responder = new Responder(onResult, onFault);
    private var someData:Array = new Array();
    private var colList:Array = new Array();

    public function GetSomeData() {}

    public function refreshSomeData():void {
        gw.connect("http://localhost/Amfphp/");         
        gw.call("GetSomeData.getData", getRes);
    }


    private function onResult(responds:Object):void {
        /****** THIS IS OUTDATED AS OF amfphp 2.x *******/
        //responds is an arrayCollection which includes .serverInfo.initialData
        //someData = responds.serverInfo.initialData;

        //this is because amfphp returns the columns in the SELECT statement out of order
        colList = ["col0", "col1", "col2", "col3", "col4", "col5", "col6", "col7"];

        for (var j:uint=0; j < colList.length; j++) {
            for (var k:uint=0; k < responds.length; k++) {
                    for(var x in responds[k]){//put columns in correct order
                        if (x.toString() == colList[j]){
                            someData[k] = new Array();
                            someData[k][j] = responds[k][x];
                            //this trace reports all of the data correctly
                            trace(someData[k][j].length);//
                        }
                    }
           }
        }

        trace(someData.length);//49
        trace(someData[0].length);//8
        trace(someData[0][0].length);//undefined

    }
}

Aucun commentaire:

Enregistrer un commentaire