Actionscript 3 如何将字符串从Php传递到VO文件,再传递到AS3中的另一个.as文件?

Actionscript 3 如何将字符串从Php传递到VO文件,再传递到AS3中的另一个.as文件?,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,大家好,我对AS3还很陌生,我正在尝试将一些数据从php解析到一个VO文件,然后将数据字符串传输到另一个.as文件中,它将把数据放入框中。我被困在如何将VO文件中的数据解析到另一个.as文件中(将数据从php拉到BookVO,然后将BookVO解析到VectorTest)。我试图在BookVO中跟踪数据,它工作正常,但我无法将数据从BookVO获取到VectorTest 请帮忙,谢谢 博克斯 package com.clark { import flash.display.*;

大家好,我对AS3还很陌生,我正在尝试将一些数据从php解析到一个VO文件,然后将数据字符串传输到另一个.as文件中,它将把数据放入框中。我被困在如何将VO文件中的数据解析到另一个.as文件中(将数据从php拉到BookVO,然后将BookVO解析到VectorTest)。我试图在BookVO中跟踪数据,它工作正常,但我无法将数据从BookVO获取到VectorTest

请帮忙,谢谢

博克斯

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 nobed1: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 function BookVO() {


            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);


            // handler for the PHP script completion and return of status
             function Jandler(event:Event) {
                 var responseVariables: URLVariables = new URLVariables(event.target.data); 
        this.nobed1 = responseVariables.nobed1 ;
        this.LoZip1 = responseVariables.LoZip1;
         this.rangelow1 = responseVariables.rangelow1;
        this.rangehigh1 = responseVariables.rangehigh1;
    }           
            }       
    }
}
向量测试

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 function VectorTest() 
        {
            super();


            var books:Vector.<BookVO> = new Vector.<BookVO>();

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

                var book:BookVO = new BookVO();
                book.nobed1 = "nobed1";
                book.LoZip1 ="LoZip1";
                book.rangelow1 = "rangelow1";
                book.rangehigh1 ="rangehigh1";
                books.push(book);

            }


            for (var j:int = 0; j < books.length; j++) 
            {
                trace("Test", j, "has a name of", books[j].nobed1);
                trace("Test", j, "Zip", books[j].LoZip1);
                trace("Test", j, "ranglow", books[j].rangelow1);
                trace("Test", j, "rangehigh", books[j].rangehigh1);
                books[j].nobed1;
                books[j].LoZip1;
                books[j].rangelow1;
                books[j].rangehigh1;
            }


            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();
                tf1.width = 100;
                var tf2: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;
                tf2.width = 100;
                tf1.y= tf.height+5;


                    // Pulling the textfields content out from the current bookVO
                tf2.text = books[k].nobed1;
                tf1.text = books[k].rangelow1;
                tf.text = books[k].rangehigh1;
                tf1.x = (Bolder.height-tf.height)*.5
                tf2.x = (Bolder.height-tf.height)*.5


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

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


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

    }

}
package com.clark
{
导入flash.display.MovieClip;
导入flash.text.TextField;
导入flash.text.textfield自动调整大小;
导入flash.text.TextFormat;
导入flash.text.TextFormatAlign;
导入flash.display.Sprite;
公共类VectorTest扩展了MovieClip
{
公共功能向量测试()
{
超级();
变量:向量。=新向量。();
对于(变量i:int=0;i
首先,你的课程做得很好。比大多数说自己是AS3新手的人要好得多

也就是说

  • VectorTest
    中,您正在调用MovieClip上的
    super()
    。你不需要这个
  • 如果您没有使用MovieClip的时间线(我建议您无论如何都不要使用),请扩展
    Sprite
    ;它很轻,因为它不携带MovieClip的时间线行李
  • 在向量测试构造函数中,您的第一个
    for循环
    循环到
    长度
    。。。没有阵列
  • 您正在覆盖该循环中
    BookVO
    的属性,该属性应该由
    urloader
    填充。这是多余的
  • 第二个循环引用了
    BookVO
    的4个属性,既不报告也不设置变量(即
    books[j].nobed1;
    )。可能想把它去掉
  • BookVO
    中,您编写了一个嵌套函数。除非你要处理大量的变量,并且变量范围有问题,否则不要这样做。目前,唯一正在访问的变量
    Jandler()
    已经是类级全局变量
加载数据是一个异步操作,这意味着数据不会立即填充(LoadRequest>Wait>ProgressEvent>Wait>LoadComplete)。因为您都在实例化
BookVO
并读取同一函数中的属性,所以您将得到的都是null属性。与
VectorTest
构造函数不同,因为
Jandler()
是在
Event.COMPLETE
(异步)上调用的,因此它可以访问您要查找的变量


试试这个。。。 您仍然需要说明要实例化多少本书的
长度
,但是,我已经将您从构造函数中读取的属性分离出来,并添加了对加载完成时要调用的方法的引用

它将打印出所有变量,如果它是向量中的最后一本书,它将调用
finish()
which。。。嗯。。。你所做的其他事情是否都完成了。:)

-干杯

BookVO更新日期2013.11.07@12:30

VectorTest

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.nobed1);
            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();
                tf1.width = 100;
                var tf2: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;
                tf2.width = 100;
                tf1.y = tf.height+5;

                // Pulling the textfields content out from the current bookVO
                tf2.text = books[k].nobed1;
                tf1.text = books[k].rangelow1;
                tf.text = books[k].rangehigh1;
                tf1.x = (Bolder.height-tf.height)*.5
                tf2.x = (Bolder.height-tf.height)*.5


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

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

                addChild(Bolder);
                currentY += Bolder.height + 35;
            }
        }
    }
}
package com.clark{
导入flash.display.MovieClip;
导入flash.text.TextField;
导入flash.text.textfield自动调整大小;
导入flash.text.TextFormat;
导入flash.text.TextFormatAlign;
导入flash.display.Sprite;
公共类VectorTest扩展了MovieClip{
公共图书:矢量。;
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.nobed1);
            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();
                tf1.width = 100;
                var tf2: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;
                tf2.width = 100;
                tf1.y = tf.height+5;

                // Pulling the textfields content out from the current bookVO
                tf2.text = books[k].nobed1;
                tf1.text = books[k].rangelow1;
                tf.text = books[k].rangehigh1;
                tf1.x = (Bolder.height-tf.height)*.5
                tf2.x = (Bolder.height-tf.height)*.5


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

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

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