Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question on Flex Components

    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

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Unless I'm missing something, or you are doing something clever that you didn't post, you have to add the component to the stage before it will display. It's not enough just to instantiate it, Flex has to be told to draw it. This would usually go something like:
    Code:
    private var myComp:MyCoolComponent = new MyCoolComponent();
    myComp.whatever = 'some setting';
    
    addChild(myComp);

  • Users who have thanked Inigoesdr for this post:

    csr_1978 (08-14-2009)

  • #3
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    adding


    addChild(myComp);

    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,

    Quote Originally Posted by Inigoesdr View Post
    Unless I'm missing something, or you are doing something clever that you didn't post, you have to add the component to the stage before it will display. It's not enough just to instantiate it, Flex has to be told to draw it. This would usually go something like:
    Code:
    private var myComp:MyCoolComponent = new MyCoolComponent();
    myComp.whatever = 'some setting';
    
    addChild(myComp);

  • #4
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    Lets say you have initState and resultState. In initState you have component1. In resultState you want component2 and not component1.

    When you switch states, do a removeChild and an addChild. Is that what you are after?
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •