0
votes

enter image description here Trying to go to the next page when a listing is clicked, but i think the name of object at the moment is not correct. I am not very sure on why the listing on stage won't be removed, i added it on a if statement.If i click it, it doesnt do anything, and if i do removeChild(newListing) then it gives me an error of access of undefined property, so i think because thats not the properties name. If i remove everything off the stage using

if(stage.numChildren > 0)
{
  stage.removeChildAt(0);
} 

then it disappear, but it doesn't add the next Child.

package com.clark

{
import com.clark.VectorTest;
    import flash.display.*;
    import flash.net.*;
    import flash.events.*;
    import flash.text.TextField;
import com.clark.TouchScroller;
    import com.clark.Viewport;
    import flash.display.Sprite;
    import flash.events.Event;
import flash.display.*;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import fl.controls.Button;
    import flash.display.MovieClip;

       public class Autoresult extends MovieClip {

        public var s1:Autoresult2 = new Autoresult2 ();
public var s3:VectorTest= new VectorTest(new Vector.<Auto>);



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

            addChild(s1);
         }



             s1.ARhome.addEventListener(MouseEvent.CLICK,home);
            s1.ARauto.addEventListener(MouseEvent.CLICK, auto);
             s1.ARsearch.addEventListener(MouseEvent.CLICK,searchss);

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



       }
            private function home (event:MouseEvent):void{
         var s5:Account = new Account ();   
    removeChild(s1);
    removeChild(newListing);

            addChild(s5);

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

            }
}
}

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;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class VectorTest extends MovieClip 
    {
          public var lists:Vector.<Listing9>;


        public function VectorTest(tests:Vector.<Auto>) 
        {

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

            {

                trace(tests[j].nobed);
                trace(tests[j].zip);
                trace(tests[j].rangelow);
                trace(tests[j].rangehigh);





        }

            var ben:int = tests ? tests.length : 0;

         lists = new Vector.<Listing9>(ben, true);
            var currentYs:int = 120;

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


                Bolder.x=40;



                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;



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


                tf.x = (Bolder.height-tf.height)*.2

                Bolder.addChild(tf);
                Bolder.addChild(tf1);
                Bolder.addChild(tf2);
                Bolder.addChild(tf3);


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



                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; 
                 lists[k] = Bolder;
                currentYs += Bolder.height + 10;
            }
        if( lists.length > 0 )
        {

            lists[0].addEventListener(MouseEvent.CLICK,gotoscener);
            lists[1].addEventListener(MouseEvent.CLICK,gotoscener1);
            lists[2].addEventListener(MouseEvent.CLICK,gotoscener2);
        }

        }
        private function gotoscener(event:MouseEvent):void{

            var s9:Autodetail = new Autodetail ();  


            addChild(s9);


       }
       private function gotoscener1(event:MouseEvent):void{

            var s9:Autodetail = new Autodetail ();  


            addChild(s9);


       }
       private function gotoscener2(event:MouseEvent):void{

            var s9:Autodetail = new Autodetail ();  


            addChild(s9);


       }
    }

}
1
You are asking about stage, but in Autoresult listing nothing about it. Also you remove newListing from the display list, but I can't see any code about adding it.Nicolas Siver
I just spent sometime on it, and realized because the listing was actually added in VectorTest.as which i edit and attached above. But the other parts is added in the Autoresult as, such as the background and buttons. I believe i have to pass the instance through from VectorTest to Autoresult? i am having trouble passing it through at the moment. Not sure if you can give me some hint on how to pass it through successfully. THanksBenyaman
Again, what problem do you have exactly? Do you want create UI components in the VectorTest and path result to the AutoResult?Nicolas Siver
At the moment the list is created from the VectorTest and background and button are added from Autoresult, what i want to do is when the list is clicked from Vector Test, the background,button everything is removed, and i add a new child. But the problem at the moment is,when i click the list from VectorTest, i can't remove the background etc added from Autoresult.Benyaman
I attached an image, when i click the orange list(that is added from VectorTest) it doesn't remove everything from stage(the background, buttons etc). I need to go to the next "page" when a list is clicked,but it doesn't at the momentBenyaman

1 Answers

0
votes

If you want manage display list, create some containers, that will help you in this task. For example, create container for the overlay UI elements, and for the content;

public var s1:Autoresult2 = new Autoresult2 ();
public var s3:VectorTest= new VectorTest(new Vector.<Auto>);
private var _overlay: Sprite;
private var _contentHolder: Sprite;

Create containers and add them to the display list:

function onadded (e:Event):void{
    _contentHolder = new Sprite();
    _overlay = new Sprite();        

    addChild(_contenHolder);
    addChild(_overlay);
    _overlay.addChild(s1);
    //If you want to hide overlay, you could set _overlay.visible = false, or remove children from the _overlay

    //Your code with buttons from s1

    if( s3.lists.length > 0 ){
        // get the first listing in the listing array
        var newListing:Listing9 = s3.lists[0];
        newListing.addEventListener(MouseEvent.CLICK, gotoscene);
        _contentHolder.addChild(newListing);
    }
}

Now, when user clicks newListing you can decide how to manage display list:

function gotoscene(e: MouseEvent):void{
    //Manage children of _contentHolder and _overlay
    //Remove everything from the _contentHolder, and add new content

    //In this example, everything will be remove from the _contentHolder
    //Will be added new content to the _contentHolder
    //overlay will be hidden for this operation
    while(_contentHolder.numChildren){
        _contentHolder.removeChildAt(0); 
    }

    _contentHolder.addChild(new Autodetail());
    _overlay.visible = false;
}