4 Replies Latest reply on Aug 14, 2009 9:33 PM by Gregory Lafrance

    Question on Flex Component

    csr_1978 Level 1

      Hi,

       

      I have two components and i am trying to display pre-defined component1 state from component2 when a button is clicked.

       

      My Code in Component2 to acheive this:

       

      private function displayComponent1():void

      {

           var comp1:Component1;

           comp1.currentState = 'addState';

      }

       

      I get this run time exception:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.

       

      so i changed my code to

       

      private function displayComponent1():void

      {

           var comp1:Component1 = new Component1();

           comp1.currentState = 'addState';

      }

       

      I dont get any exceptions but its not displaying component1. Can any one please help me out.

       

      Thanks,

      csr

        • 1. Re: Question on Flex Component
          FlexAppsStore.com

          Hello,

           

               If I understand what you are looking, it sounds like you need to use the full domain path when setting the state.

           

          For example:

           

          private function displayComp():void {

           

               com.mycomps.comp1.currentState = 'addState';

           

          }

           

          This assumes that you have setup an XMLNS for you comps.

           

           

          Kind regards,

           

          Ivan Alexander

          FlexAppsStore.com

          • 2. Re: Question on Flex Component
            Gregory Lafrance Level 6

            You need to use addChild() to add comp1 to the display list:

             

            private function displayComponent1():void{
                var comp1:Component1 = new Component1();
                comp1.currentState = 'addState';
                this.addChild(comp1);
            }
            
            

             

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

            1 person found this helpful
            • 3. Re: Question on Flex Component
              csr_1978 Level 1

              adding

              this.addChild(comp1);

              works but this adds component1 inside component2 so i get two panels displayed one from component1 and other from component2 but i just want to display component1. is there any way that i can just forward it to component1?

               

              Thanks,

              • 4. Re: Question on Flex Component
                Gregory Lafrance Level 6

                I'm not exactly sure what you are trying to do. You seem to have a main app, and component 1 and component 2.

                 

                If you are trying to add component1 to the main app instead of to component2, then:

                 

                mx.core.Application.application.addChild(comp1);

                 

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