3 Replies Latest reply on Nov 13, 2009 9:50 AM by lee704

    Uninstantiate View in ViewStack?

    lee704 Level 1

      I have an application with several ViewStacks and a lot of Views.  When the ViewStack is called, I understand that the Views are created as called.  I know that you can force call all the Views by using the createionPolicy attribute of the ViewStack tag.  This is great except that after the Views are created, they stay created until the movie stops.


      Instead, I would like the Views to somehow uninstantiate or be forced to recreate after the View has lost focus.  For example, in a View I have a form that collects information.  The user types information in the form and then leaves the form (say to go to another view) before clicking a submit button.  When the user returns to the form, I want all the information previously entered in the form to be gone as if the form just opened for the first time.


      I assume there is an easy way to do this using some part of the ViewStack functionality, but I don't know how.


      Any ideas?

        • 1. Re: Uninstantiate View in ViewStack?
          Gregory Lafrance Level 6

          If this post answers your question or helps, please mark it as such.


          Usually in this case you use the "show" event. The handler can do something like this to reset all data in a view:


          private function clearScreen():void{
          public function doClearScreen(c:Container):void{
            for each(var obj:Object in c.getChildren()){
          private function clearObjects(item:*):void{
            if(item is Container){
              for each(var child:Object in item.getChildren()){
              if(item is TextInput){
                item.text = ""
              }else if(item is ComboBox){
                item.selectedIndex = 0;
          • 2. Re: Uninstantiate View in ViewStack?
            lee704 Level 1

            Thanks for all your help Greg.  I am getting an error when I insert the code you provided in my control.  The error is:


            1046: Type was not found or was not a compile-time constant: Container.


            Can you provide a suggestion?



            • 3. Re: Uninstantiate View in ViewStack?
              lee704 Level 1

              Cancel my last post.  I needed to import the Container class (import mx.core.Container;).  Just a note for anyone that wants to use the code Greg provided, you need to replace contactInfoHb in the example with the id of the container object you want to clear.


              Thanks again Greg!!!