Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-13-2009, 10:30 PM   PM User | #1
csr_1978
New to the CF scene

 
Join Date: Aug 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
csr_1978 is an unknown quantity at this point
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
csr_1978 is offline   Reply With Quote
Old 08-14-2009, 04:49 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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);
Inigoesdr is offline   Reply With Quote
Users who have thanked Inigoesdr for this post:
csr_1978 (08-14-2009)
Old 08-14-2009, 01:35 PM   PM User | #3
csr_1978
New to the CF scene

 
Join Date: Aug 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
csr_1978 is an unknown quantity at this point
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);
csr_1978 is offline   Reply With Quote
Old 08-14-2009, 03:55 PM   PM User | #4
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,049
Thanks: 9
Thanked 82 Times in 82 Posts
jerry62704 is on a distinguished road
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
jerry62704 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:57 PM.


Advertisement
Log in to turn off these ads.