The generated class doesn't look like that. Instead, the MXML compiler
creates a tree of UIComponentDescriptor instances in order to support a
feature of Flex known as deferred instantiation.
 
BTW, another reason that the children don't get created at 'new' time is
that inherited styles aren't known until the component is attached to
its ancestors by addChild().
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of bhaq1972
Sent: Monday, April 30, 2007 1:50 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: creating instances, addChild question



thanks for the input Gordon,

When i think of creating mxml components, i'm thinking 
lazy/convenience programming.

i want all the component and its children to be created. I can give 
the children some default values which i can then change after 
the 'new', if i wish

eg My PrintView.mxml
<mx:VBox backgroundColor='yellow'>
<mx:Label id='contact' text='batman'/>
<mx:PrintDataGrid id="printDG"/>
</mx:VBox>

in code -
var printView:MyPrintView = new PrintView();
// change what i like
printView.contact.text = 'spiderman';
etc.

i thought the generated AS class would look like this

class MyPrintView extends VBox
{
public contact:Label;
public printDG:PrintDataGrid

public MyPrintView()
{
super();

contact = new Label();
contact.text = 'batman'
addChild(contact)
//etc
}
}

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> > when i create an instance of MyPrintView, its children are not
> created. why is that?
> > if you addChild() to the Application....they are created. why is 
that?
> 
> The reason that components do not create their children immediately 
when
> they are created is so that you can set properties after 
calling 'new'
> and have these properties affect which children get created. For
> example,
> 
> var clock:Clock = new Clock();
> clock.mode = "analog";
> addChild(clock);
> 
> The Clock would need completely different children if the mode were
> "digital" instead of "analog". By delaying the creation of the 
children
> until addChild(), the framework makes it possible to optimize which
> children are created.
> 
> - Gordon
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>

[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of bhaq1972
> Sent: Monday, April 30, 2007 4:57 AM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] creating instances, addChild question
> 
> 
> 
> This question is very similar to a question someone else is asking 
> (may even be the same thing????)
> 
> I've got a component called MyPrintView.mxml
> 
> <mx:VBox>
> <mx:Label id="contact"/>
> <mx:PrintDataGrid id="printDG"/>
> </mx:VBox>
> 
> when i create an instance of MyPrintView, its children are not 
> created. why is that?
> 
> if you addChild() to the Application....they are created. why is 
> that?
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > " 
> initialize="startUP()">
> 
> <mx:Script>
> <![CDATA[
> private function startUP():void
> {
> var printView:MyPrintView = new MyPrintView();
> trace(printView); 
> trace(printView.printDG, printView.contact); //both null
> addChild(printView); 
> trace(printView.printDG, printView.contact); //both not null
> 
> }
> ]]>
> </mx:Script>
> </mx:Application>
>



 

Reply via email to