...

View Full Version : Question on Flex Components



csr_1978
08-13-2009, 10:30 PM
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

Inigoesdr
08-14-2009, 04:49 AM
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:

private var myComp:MyCoolComponent = new MyCoolComponent();
myComp.whatever = 'some setting';

addChild(myComp);

csr_1978
08-14-2009, 01:35 PM
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,


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:

private var myComp:MyCoolComponent = new MyCoolComponent();
myComp.whatever = 'some setting';

addChild(myComp);

jerry62704
08-14-2009, 03:55 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum