0
votes

I am trying to add a movieclip that is generated through a loop from SearchVectorTest class file, and put that into sresultnologin class file. Then i will make that movieclip clickable, and when clicked, goes to next class,display a new stage, pull the information from that specific stored in that movieclip, and pull the rest of the information from the database and display them.

I am having an error at the moment, Type not found. I can't seem to add the Movieclip(box) as a button. on this line var newListing:Listing2 = Bolder.getChildAt(0);

sresultnologin.as

    package com.clark

{
import com.clark.SearchVectorTest;
    import flash.display.*;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import fl.controls.Button;
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;




       public class sresultnologin extends MovieClip {

public var s1:Searchreult = new Searchreult ();

               public function sresultnologin(){
                  // init



            addEventListener(Event.ADDED_TO_STAGE, onadded);
         function onadded (event:Event):void{



            s1.x=-10;
            s1.y=10;

            addChild(s1);
         }

var s3:SearchVectorTest= new SearchVectorTest(new Vector.<searchVO1>);
                 addChild (s3);


            s1.SRhome.addEventListener(MouseEvent.CLICK, fl_ClickToGoTol);
            s1.ARsearch.addEventListener(MouseEvent.CLICK, fl_ClickToGosearch);

 if( s3.listings.length > 0 )
        {
            // get the first listing in the listing array
            var newListing:Listing8 = s3.listings[0];
            newListing.addEventListener(MouseEvent.CLICK, gotoscener);
        }
        else
        {



        }


           }

               // private methods
           private function gotoscener(event:MouseEvent):void
        {

            var s9:Listingdetail = new Listingdetail ();    
    removeChild(s1);
            addChild(s9);


       }


        private function fl_ClickToGoTol(event:MouseEvent):void
        {

            var s9:Account = new Account ();    
    removeChild(s1);
            addChild(s9);

        }

        private function fl_ClickToGosearch(event:MouseEvent):void
        {

            var s9:searchVO1 = new searchVO1 ();    
    removeChild(s1);
            addChild(s9);


       }

}
}

SearchVectorTest.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;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class SearchVectorTest extends MovieClip 
    {
        public var listings:Vector.<Listing8>;

        public function SearchVectorTest(test:Vector.<searchVO1>) 
        {

for (var j:int = 0; j < test.length; j++) 
            {


                trace(test[j].nobed);
                trace(test[j].zip);
                trace(test[j].Location);
                trace(test[j].price);

        }

            var len:int = test ? test.length : 0;
         // create your vector for your listings with the len size
         listings = new Vector.<Listing8>(len, true);
            var currentY:int = 200;

            for (var k:int = 0; k < test.length; k++) 
            {
                var Bolder:Listing8 = new Listing8();

                Bolder.x=20;

                var bf:TextField = new TextField();
                var bf1:TextField = new TextField();
                var bf2:TextField = new TextField();
                var bf3:TextField = new TextField();

                bf3.width = 100;
                bf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);

                bf.width = 100;
                bf.autoSize = TextFieldAutoSize.CENTER;
                bf1.width = 100;
                bf1.autoSize = TextFieldAutoSize.CENTER;
                bf2.autoSize = TextFieldAutoSize.CENTER;
                bf3.autoSize = TextFieldAutoSize.CENTER;
                bf3.width = 100;
                bf1.y= bf.height+5;


                bf.text = test[k].nobed;
                bf1.text = test[k].zip;
                bf2.text = test[k].Location;
                bf3.text = test[k].price;

                bf.x = (Bolder.height-bf.height)*.2
                Bolder.addChild(bf);
                Bolder.addChild(bf1);
                Bolder.addChild(bf2);
                Bolder.addChild(bf3);
                Bolder.properties = test[k].nobed;
                Bolder.properties = test[k].zip;

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


                addChild(Bolder);
                 Bolder.mouseChildren = false;    // ignore children mouseEvents
            Bolder.mouseEnabled = true;      // enable mouse on the object - normally set to true by default
            Bolder.useHandCursor = true;     // add hand cursor on mouse over
            Bolder.buttonMode = true; 
                 listings[k] = Bolder;
                currentY += Bolder.height + 10;
            }

        }


    }

}

SearchVO1

package com.clark
{

    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import fl.controls.Button;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLVariables;
    import flash.utils.*;
    import flash.sampler.NewObjectSample;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
    import flash.text.TextFormatAlign;



       public class searchVO1 extends MovieClip {
        private var Arvariables:URLVariables;
        private var SrSend:URLRequest;
        private var SaLoader:URLLoader;
           public var nobed:String;
        public var zip:String;
        public var Location:String;
        public var price:String;
           public var callMethod:Function;

public var s1:searchpage = new searchpage ();

               public function searchVO1():void{

addEventListener(Event.ADDED_TO_STAGE, onadded);                  // init
function onadded (event:Event):void{


            s1.x=-10;
            s1.y=10;

            addChild(s1);
             s1.account.addEventListener(MouseEvent.CLICK, fl_ClickToGoToaccount);
             s1.searchs.addEventListener(MouseEvent.CLICK, ValidateAndsearch);
            s1.Au.addEventListener(MouseEvent.CLICK, fl_ClickToGoToautomatch);
            s1.setting.addEventListener(MouseEvent.CLICK, fl_ClickToGoToss);
            s1.Shome.addEventListener(MouseEvent.CLICK, fl_ClickToGoTohom);




            // Build the varSend variable
            SrSend = new URLRequest("http://localhost/search.php");
            SrSend.method = URLRequestMethod.POST;
                   Arvariables = new URLVariables;
            SrSend.data = Arvariables;

            SaLoader = new URLLoader();
            SaLoader.dataFormat = URLLoaderDataFormat.TEXT;
            SaLoader.addEventListener(Event.COMPLETE,Asandler);


 // private methods

           function Asandler(event:Event):void{

 // retrieve data from php call
var resultString :String = event.target.data;
// parse result string as json object and cast it to array
var resultArray  :Array  = JSON.parse( resultString ) as Array;
// get the length of the result set
var len:int = resultArray.length;

// create vector of SearchVO
var searchVOs:Vector.<searchVO1> = new Vector.<searchVO1>();
// loop the result array
               var i:int;
for(i=0; i<len; i++ )
{
    searchVOs[i] = new searchVO1();   
    searchVOs[i].nobed = resultArray[i].nobed;
    searchVOs[i].zip = resultArray[i].zip;
    searchVOs[i].Location = resultArray[i].Location;
    searchVOs[i].price =  resultArray[i].price;
}

// call a function to create your boxes

// or maybe create your SearchVector class and pass it your search vector
var mySearchVector:SearchVectorTest = new SearchVectorTest(searchVOs);
addChild(mySearchVector);
       }   
   }
   }

    public function searchVOs( nobed:String, zip:String, location:String, price:String )
        {
            this.nobed      = nobed;
            this.zip        = zip;
            this.Location   = Location;
            this.price      = price;
        }
        public function ValidateAndsearch (event:MouseEvent):void {

        // validate fields

         Arvariables.nobed = s1.nobed.text;
        Arvariables.zip = s1.zip.text;
            Arvariables.Location = s1.Location.text;
            Arvariables.price = s1.price.text;
    SaLoader.load(SrSend);
            var s7:sresultnologin = new sresultnologin()    
    removeChild(s1);
            addChild(s7);




        }
         // close else condition for error handling

         // close validate and send function





        private function fl_ClickToGoToautomatch(event:MouseEvent):void
        {
            var s7:Auto = new Auto ();  
    removeChild(s1);
            addChild(s7);
        }

        private function fl_ClickToGoToss(event:MouseEvent):void
        {
            //
        }
        private function fl_ClickToGoToaccount(event:MouseEvent):void
        {
            var s7:Account = new Account ();    
    removeChild(s1);
            addChild(s7);
        }



        private function fl_ClickToGoTohom(event:MouseEvent):void
        {

            var s7:homepage = new homepage ();  
    removeChild(s1);
            addChild(s7);

        }


       }

}
1

1 Answers

0
votes

i think you have to remove these lines:

public var Bolder:MovieClip;
public var Listing2:MovieClip;

and try to get your Listing2 object like this:

var newListing:Listing2 = s3.getChildAt(0);

but if you want to access your listings in the SearchVectorTest class it's better to keep a public reference of them like this (maybe in an array or a vector):

SearchVectortest class:

public class SearchVectorTest extends MovieClip 
{
    /** the array of listings **/
    public var listings:Vector.<Listing2>;

    public function SearchVectorTest(test:Vector.<searchVO1>) 
    {
         // put the array length in a variable -> if test = null make len = 0
         var len:int = test ? test.length : 0;
         // create your vector for your listings with the len size
         listings = new Vector.<Listing2>(len, true);
         // ...
         for( var k:int = 0; k < len; k++ ) 
         {
            var bolder:Listing2 = new Listing2();

            bolder.mouseChildren = false;    // ignore children mouseEvents
            bolder.mouseEnabled = true;      // enable mouse on the object - normally set to true by default
            bolder.useHandCursor = true;     // add hand cursor on mouse over
            bolder.buttonMode = true;        // this must be set to true to have hand cursor
            // add your linsting to the vector
            listings[k] = bolder;
            //...
         }
         // ...
    }
}

after that you could get your listing like this:

sresultnologin.as

public class sresultnologin extends MovieClip 
{
    public var s1           :Searchreult = new Searchreult ();

    //public var Bolder     :MovieClip;     // never used -> useless
    //public var Listing2   :MovieClip;     // never used -> useless

    public function sresultnologin()
    {
        // init
        addEventListener(Event.ADDED_TO_STAGE, onadded);

        function onadded (event:Event):void
        {
            s1.x=-10;
            s1.y=10;

            addChild(s1);
        }

        var s3:SearchVectorTest= new SearchVectorTest(new Vector.<searchVO1>);
        addChild (s3);

        s1.SRhome.addEventListener(MouseEvent.CLICK, fl_ClickToGoTol);
        s1.ARsearch.addEventListener(MouseEvent.CLICK, fl_ClickToGosearch);

        // verify if there are enties in the array
        if( s3.listings.length > 0 )
        {
            // get the first listing in the listing array
            var newListing:Listing2 = s3.listings[0];
            newListing.addEventListener(MouseEvent.CLICK, goto);
        }
        else
        {
            // do something if there are no results
        }
    }
    //...
}

hope that helps ;)