1

我对 AS3 和 php 很陌生。尝试将数组从 Php 传递到 AS3 VO 文件,然后将其解析为 Vector,然后将它们打包在盒子中。发生了一件非常奇怪的事情,通过的第一个变量始终为空,我调换了位置,第一个变量仍然为空。但其余的变量都很好。如果有人可以解决我的问题,将非常感谢!忽略任何可能的 SQLi 注入问题,我还没有时间改变这些。谢谢!

php

<?php
ini_set('display_errors', 1); error_reporting(E_ALL);

session_start();

include 'connect.php';


$_SESSION['username'];
$username=$_SESSION['username'];


$result=mysqli_query($con,"SELECT * FROM Test WHERE username = '$username'")or die( mysqli_error($con));
$solutions = array();
$check_num_rows=mysqli_num_rows($result);

while ($row = mysqli_fetch_assoc($result))
{

        $solutions[5]=$row['LoZip1'];
      $solutions[2]=$row['rangelow1'];
       $solutions[3]=$row['rangehigh1'];
       $solutions[4]=$row['nobed1'];
}

echo "rangelow1=".$solutions[2];
echo "&rangehigh1=". $solutions[3];
echo "&bed1=".$solutions[4];
echo "&LoZip1=".$solutions[5];
?>

BookVO.as

package  com.clark
{   
    import flash.display.*;
    import flash.net.*;
    import flash.events.*;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLVariables;


    public class BookVO 
    {
        public var bed1:String;
        public var LoZip1:String;
        public var rangelow1:String;
        public var rangehigh1:String;
        public var Bend:URLRequest;
        public var variabless:URLVariables;
        public var nLoader:URLLoader;
        public var callMethod:Function;


        public function BookVO(listener:Function = null)  {


            Bend = new URLRequest("http://localhost/Autoresult.php");
            Bend.method = URLRequestMethod.POST;



            variabless = new URLVariables();
            Bend.data = variabless;


            nLoader = new URLLoader();
            nLoader.dataFormat = URLLoaderDataFormat.TEXT;
            nLoader.addEventListener(Event.COMPLETE,Jandler);
            nLoader.load(Bend);
              if (listener != null) {
                callMethod = listener;
            }
        }

             public function Jandler(event:Event) {
            // handler for the PHP script completion and return of status
            var responseVariables:URLVariables = new URLVariables(event.target.data);
            bed1 = responseVariables.bed1 ;
            LoZip1 = responseVariables.LoZip1;
            rangelow1 = responseVariables.rangelow1;
            rangehigh1 = responseVariables.rangehigh1;

            if (callMethod != null) {
                callMethod(this);
                       }        
            }

    }

}

向量测试

package  com.clark
{
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
    import flash.display.Sprite;

    public class VectorTest extends MovieClip 
    {
          public var books:Vector.<BookVO>;
        public function VectorTest() 
        {
    books = new Vector.<BookVO>();

            for (var i:int = 0; i <length; i++) 
            {

            var book:BookVO = new BookVO(response);     
                books.push(book);


            }
        }


            private function response(book:BookVO):void
            {
                trace("Name:",book.bed1);
                trace("Zip:", book.LoZip1);
                trace("ranglow:", book.rangelow1);
                trace("rangehigh:", book.rangehigh1);
                 // call finish() if this is the last book.
                 if (books.indexOf(book) == books.length - 1) {
                finish();
            }
            }


            private function finish():void {
            var currentY:int = 270;

            for (var k:int = 0; k < books.length; k++) 
            {
                var Bolder:Listing2 = new Listing2();
                Bolder.x=80;

                var tf:TextField = new TextField();
                var tf1:TextField = new TextField();
                var tf2:TextField = new TextField();
                var tf3:TextField = new TextField();
                tf2.width = 100;
                tf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);

                tf.width = 100;
                tf.autoSize = TextFieldAutoSize.CENTER;
                tf1.width = 100;
                tf1.autoSize = TextFieldAutoSize.CENTER;
                tf2.autoSize = TextFieldAutoSize.CENTER;
                tf3.autoSize = TextFieldAutoSize.CENTER;
                tf2.width = 100;
                tf1.y= tf.height+5;


                    // Pulling the textfields content out from the current bookVO

                tf.text = books[k].bed1;
                tf1.text = books[k].LoZip1;
                tf2.text = books[k].rangelow1;
                tf3.text = books[k].rangehigh1;
                tf1.x = (Bolder.height-tf.height)*.5
                tf2.x = (Bolder.height-tf.height)*.5
                tf3.x = (Bolder.height-tf.height)*.5


                tf.x = (Bolder.height-tf.height)*.5
                tf.y = (Bolder.height-tf.height)*.5
                Bolder.addChild(tf);
                Bolder.addChild(tf1);
                Bolder.addChild(tf2);
                Bolder.addChild(tf3);

                    // position the object based on the accumulating variable.
                Bolder.y = currentY;

                addChild(Bolder);
                currentY += Bolder.height + 35;
            }



        }

    }

}
4

1 回答 1

1

我有这个简单的测试代码和你的测试数据:

var s:String = "rangelow1=b&rangehigh1=bb&bed1=a&LoZip1=bb"; 
var u:URLVariables = new URLVariables(s); 
trace(u.bed1, u.LoZip1, u.rangelow1, u.rangehigh1); 

而且它们都没有显示为空。所以解析看起来还可以,但是下面的逻辑是错误的:

if (books.indexOf(book) == books.length - 1) {
    finish()
}

URLLoader异步加载数据,因此不能保证所有书籍都会按照您请求的顺序加载。根据网络连接,最后一本书的数据可能会在前一本书的数据之前加载。在这种情况下,您将在finish. 为了解决这个问题,而不是indexof使用计数器变量来计算加载了多少本书并调用finish一次counter == books.length

var counter:int = 0;

private function response(book:BookVO):void {
    counter++;

    if (counter == books.length) {
        finish();
    }
}
于 2013-11-07T08:42:17.707 回答