1
votes

I am new to AS3, and i am trying to do a search type file in php(to pull info that matches a username) and return the result in AS3. The php returns all variables into AS3, except for the first one that enters,when it loops the second time, all variables passes through ok. I am also trying to do a multiple fields search and return the results in AS3 with similar principles but same issue is occurring. Please help me see if it is a php error or AS3 issue.Thanks for your time

Autoresult.php

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

session_start();

include 'connect.php';



$username=$_SESSION['username'];


$result=mysqli_query($con,"SELECT * FROM Automatch WHERE username = '$username'")or die( mysqli_error($con));
$solutions = array();
while ($row = mysqli_fetch_assoc($result))
        {

          print "nobed=".$solutions[0]=$row['nobed'];
        print "&zip=".$solutions[1]=$row['zip'];
      print "&rangelow=".$solutions[2]=$row['rangelow'];
     print "&rangehigh=".$solutions[3]=$row['rangehigh'];
        }

        ?>

BookVo2.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 BookVO2 
    {
        public var nobed:String;
        public var zip:String;
        public var rangelow:String;
        public var rangehigh:String;
        public var Bend:URLRequest;
        public var variabless:URLVariables;
        public var nLoader:URLLoader;
        public var callMethod:Function;


        public function BookVO2(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);
           nobed = responseVariables.nobed ;
            zip = responseVariables.zip;
           rangelow = responseVariables.rangelow;
            rangehigh = responseVariables.rangehigh;

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

    }
        }

    }

}

VectorTest.as

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.<BookVO2>;
        public var counter:int = 0;
        public function VectorTest() 
        {

            books = new Vector.<BookVO2>();

            {

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


        }


            private function response(book:BookVO2):void

            {

                trace("Name:",book.nobed);
                trace("Zip:", book.zip);
                trace("rangelow:", book.rangelow);
                trace("rangehigh:", book.rangehigh);


                 // call finish() if this is the last book.

                counter++;

    if (counter == books.length) {
        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();

                tf3.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;
                tf3.width = 100;
                tf1.y= tf.height+5;



                    // Pulling the textfields content out from the current bookVO

                tf.text = books[k].nobed;
                tf1.text = books[k].zip;
                tf2.text = books[k].rangelow;
                tf3.text = books[k].rangehigh;

                tf1.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)*.15
                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;
            }

        }

    }

}
2
the error is an as3 error, well thats what you have given me, it means the text box is expecting something but you are giving it nothing....also with your php you would not have to print all them lines or variables, push all the items into an array and build a http string. - joshua
I am coming to think it is the way i put the php, because the nobed string has merged into the rangehigh string as such rangehigh: fsefesnobed=test,testnobed=ben,test Not sure how do i fix it, and that i cant add a & sign before the nobed as it is the first variable - Benyaman
The situation is like this, this is the output. Name: null Zip: sef,tes,ben rangelow: sefse,tes,ben rangehigh: fsefesnobed=test,testnobed=ben,test So there is things coming in from php except the first one, the name, but the name has merged into the rangehigh as it loops. - Benyaman

2 Answers

0
votes

Try something like that:

tf.text = books[k].nobed || '';
tf1.text = books[k].zip || '';
tf2.text = books[k].rangelow || '';
tf3.text = books[k].rangehigh || '';

or maybe this:

tf.text = "";
if ( books[k].nobed !== null ) tf.text = books[k].nobed;
etc...
0
votes

Declare variabless = new URLVariables();

as

var variables:URLVariables = new URLVariables();

Instantiate the varibles buddy.