3 Replies Latest reply on Oct 7, 2010 2:42 AM by RaúlKirm

    How to know if a element exists?

    RaúlKirm Level 1

      Hi!, I have an Flex 4 proyect, and in the .mxml file I have something like this:

       

      <s:BorderContainer id="PCDock"  ....
      ....
      

       

      By code, fired by an event, I remove that element with:

       

       removeElement(PCDock);
      

       

      and can add it to stage with:

       

       addElement(PCDock);
      

       

       

      but, how can I know if my element "PCDock" exists in the stage?

       

      Thanks!

        • 1. Re: How to know if a element exists?
          BhaskerChari Level 4

          You can check the condition as below..

           

          if(this.getChildByName("PCDock") != null)

          {

               //then PCDock element exists

          }

          else

          {

               //then PCDock element doesn't exists

          }

           

           

           

          Thanks,

          Bhasker

          1 person found this helpful
          • 2. Re: How to know if a element exists?
            RaúlKirm Level 1

            Thanks for your answer Bhasker, I have write this:

             

            if (this.getElementIndex(PCDock)<0){
                    addElement(PCDock);
             }
                    
            

             

             

            but that throw this error:

             

            ArgumentError: PCDock is not found in this Group.
            

             

             

            whats the meaning of that error. I have googled the error and dont find anynthing...

             

            any Idea???

            • 3. Re: How to know if a element exists?
              BhaskerChari Level 4

              Hi RaúlKirm,

               

              Here this  refers to main application.

               

              If you have placed PCDock directly in your <s:Application /> container then you can use this.getElementIndex(PCDock), but if you have placed in another container then it will throw an error since it doesn't belong to Application directly but a subchild of it.

               

               

              Say if your BorderContainer  is in another conatiner as something below then you need to use as shown below:

              <s:SomeContainer id="PCDockConatiner">
                   <s:BorderContainer id="PCDock"  ....

              </s:SomeContainer>

               

              So here you need to use PCDockConatiner.getElementIndex(PCDock) instead of this.getElementIndex(PCDock) since PCDock  is not the direct child of Application container but of PCDockConatiner.

               

              if (PCDockConatiner.getElementIndex(PCDock)<0){
                      addElement(PCDock);
              }

               

              Thanks,

              Bhasker