You could try changing .visible and .includeInLayout instead of
adding/removing.

 

The best practice for resolving multiple properties is to use the
invalidateProperties/commitProperties technique.

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Sean Sell
Sent: Tuesday, June 05, 2007 11:13 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: Selecting which Child Components to add at
runtime

 

Not quite. I have items 0 through 5 I want them to be displayed in that
order but if 4 is not displayed then I get an out of bounds error when I
addChild At 5. It may happen when 2 is drawn even if 0 and 1 are going
to be drawn but since I have no control over order it evaluates the
variables in the MXML invocation that will generate an error also

i.e.

<reportComps:OrderBy id="userOrderBy" 
                showAssociate="true" showArrival="true"
showPDeparture="true" showHost="true"/>

----- Original Message ----
From: Alex Harui <[EMAIL PROTECTED]>
To: flexcoders@yahoogroups.com
Sent: Tuesday, June 5, 2007 1:20:41 PM
Subject: RE: [flexcoders] Re: Selecting which Child Components to add at
runtime

The order of items in HBox/VBox is their childIndex order.
addChildAt(myButton , 0) should put it first.

 

________________________________

From: [EMAIL PROTECTED] ups.com [mailto:flexcoders@ yahoogroups. com]
On Behalf Of rough68fish
Sent: Tuesday, June 05, 2007 10:05 AM
To: [EMAIL PROTECTED] ups.com
Subject: [flexcoders] Re: Selecting which Child Components to add at
runtime

 

When showAssociate is set to true the button shows up, but I want it
always to show up first.

Here's my code:
<?xml version="1.0" encoding="utf- 8"?>
<mx:HBox xmlns:mx="http://www.adobe. com/2006/ mxml
<http://www.adobe.com/2006/mxml> ">

<mx:Script>
<![CDATA[
import mx.controls. RadioButton;

// Associate Order By
public function set showAssociate( val : Boolean) : void {
if (val == true) {
var myButton : RadioButton =
getNewButton( "associateRB" ,
"Associate Name", "Associate") ;
myButton.selected = true;
this.addChild( myButton) ;
} else {
if (this.getChildByNam e("associateRB" ) != null) {

this.removeChild( this.getChildByN ame("associateRB "));
}
}
}

// Host Order By
public function set showHost(val : Boolean) : void {
if (val == true) {
var myButton : RadioButton = getNewButton( "hostRB",
"Host Name", "Host");
this.addChild( myButton) ;
} else {
if (this.getChildByNam e("hostRB" ) != null) {
this.removeChild( this.getChildByN ame("hostRB" ));
}
}
}

// Arrival Order By
public function set showArrival( val : Boolean) : void {
if (val == true) {
var myButton : RadioButton =
getNewButton( "arrivalRB" ,
"Arrival Date", "Arrival");
this.addChild( myButton) ;
} else {
if (this.getChildByNam e("arrivalRB" ) != null) {

this.removeChild( this.getChildByN ame("arrivalRB" ));
}
}
}

// Departure Order By
public function set showDeparture( val : Boolean) : void {
if (val == true) {
var myButton : RadioButton =
getNewButton( "departureRB" ,
"Departure Date", "Departure") ;
this.addChild( myButton) ;
} else {
if (this.getChildByNam e("departureRB" ) != null) {

this.removeChild( this.getChildByN ame("departureRB "));
}
}
}

// Pending Arrival Order By
public function set showPArrival( val : Boolean) : void {
if (val == true) {
var myButton : RadioButton =
getNewButton( "pArrivalRB" ,
"Pending Arrival Date", "PArrival");
this.addChild( myButton) ;
} else {
if (this.getChildByNam e("pArrivalRB" ) != null) {

this.removeChild( this.getChildByN ame("pArrivalRB" ));
}
}
}

// Pending Departure Order By
public function set showPDeparture( val : Boolean) : void {
if (val == true) {
var myButton : RadioButton =
getNewButton( "pDepartureRB" ,
"Pending Departure Date", "PDeparture" );
this.addChild( myButton) ;
} else {
if (this.getChildByNam e("pDepartureRB" ) != null) {

this.removeChild( this.getChildByN ame("pDepartureR B"));
}
}
}

protected function getNewButton( id : String, label : String,
value : String) : RadioButton {
var myButton : RadioButton = new RadioButton( );
myButton.id = id;
myButton.groupName = "orderByGrp" ;
myButton.label = label;
myButton.value = value;

return myButton;
}

public function reset() : void {
if (this.getChildByNam e("associateRB" ) != null) {

RadioButton( this.getChildByN ame("associateRB ")).selected = true;
}
}
]]>
</mx:Script>

<mx:RadioButtonGrou p id="orderByGrp" />
<!--mx:RadioButton id="associateRB" groupName="orderByG rp"
label="Associate Name"
value="Associate" visible="{this. showAssociate} "
selected="true" /-->
<!--mx:RadioButton id="hostRB" groupName="orderByG rp" label="Host
Name"
value="Host" visible="{this. showHost} "/-->
<!--mx:RadioButton id="arrivalRB" groupName="orderByG rp"
label="Arrival Date"
value="Arrival" visible="{this. showArrival} "/-->
<!--mx:RadioButton id="departureRB" groupName="orderByG rp"
label="Departure Date"
value="Departure" visible="{this. showDeparture} "/-->
<!--mx:RadioButton id="pArrivalRB" groupName="orderByG rp"
label="Pending Arrival Date"
value="PArrival" visible="{this. showPArrival} "/-->
<!--mx:RadioButton id="pDepartureRB" groupName="orderByG rp"
label="Pending Departure Date"
value="PDeparture" visible="{this. showPDeparture} "/-->
</mx:HBox>

--- In [EMAIL PROTECTED] ups.com <mailto:flexcoders%40yahoogroups.com>
, "rough68fish" <rough68fish@ ...>
wrote:
>
> Can you extend this concept slightly for me. I have several dynamic
> items to display in the view (whether they are displayed is controled
> through binding and set functions) this works.
>
> I just can figure out how to control the order that they are drawn on
> the page.
>
>
>
> --- In [EMAIL PROTECTED] ups.com
<mailto:flexcoders%40yahoogroups.com> , "Alex Harui" aharui@ wrote:
> >
> > Are you asking about:
> >
> >
> >
> > private function fAddCustomView( compClass: Class):void
> > {
> > var canCustView: Container = Container(new compClass()) ;
> > canCustView. label = "Custom " +
> > cbCompList.selected Item.label;
> > vsComps.addChild( canCustView) ;
> > }
> >
> >
> >
> > ...
> >
> > fAddCustomView( Comp1);
> >
> >
> >
> >
> >
> > ____________ _________ _________ __
> >
> > From: [EMAIL PROTECTED] ups.com
<mailto:flexcoders%40yahoogroups.com>  [mailto:[EMAIL PROTECTED]
ups.com <mailto:flexcoders%40yahoogroups.com> ]
On
> > Behalf Of phall121
> > Sent: Monday, June 04, 2007 12:39 PM
> > To: [EMAIL PROTECTED] ups.com
<mailto:flexcoders%40yahoogroups.com> 
> > Subject: [flexcoders] Selecting which Child Components to add at
runtime
> >
> >
> >
> > I want to add views to a ViewStack at runtime by selecting from an
> > expanding table of Custom Components.
> >
> > As the simplified code below shows, I can figure out how to add any
> > one and hard code it. But the addChild method of the ViewStack
> > seems to require that you know ahead of time which component you
> > want to add. I can not find in the docs or online a way to make
> > this dynamic.
> >
> > In other words, when I define the new component view to add to the
> > view stack....
> > {
> > var canCustView: Comp1 = new Comp1();
> > canCustView. label = "Custom " + cbCompList.selected Item.label;
> > vsComps.addChild( canCustView) ;
> > }
> > ...I want to choose at runtime whether to instantiate views from
> > Comp1, Comp17, or Comp53, etc.
> >
> > Any ideas how to accomplish this? Thanks for your thoughts!
> >
> > Here is the simplified code.
> >
> > <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> >
"
> > layout="absolute"
> > xmlns:comp=" components. *">
> >
> > <mx:Script>
> > <![CDATA[
> > import components.* ;
> >
> > private function fAddView():void
> > {
> > var canHardView: TestComp = new TestComp();
> > canHardView. label = "Hard-Code View2";
> > vsComps.addChild( canHardView) ;
> > }
> >
> > private function fAddCustomView( ):void
> > {
> > var canCustView: Comp1 = new Comp1();
> > canCustView. label = "Custom " +
> > cbCompList.selected Item.label;
> > vsComps.addChild( canCustView) ;
> > }
> >
> > ]]>
> > </mx:Script>
> >
> > <mx:Button x="25" y="36" label="Add Hard-Coded View"
> > click="fAddView( )"/>
> >
> > <mx:Button x="25" y="68" label="Add Custom Component"
> > click="fAddCustomVi ew()"/>
> >
> > <mx:ComboBox id="cbCompList" x="203" y="67">
> > <mx:dataProvider>
> > <mx:Array id="arrCompList" >
> > <mx:Object label="Component1" data="Comp1" />
> > <mx:Object label="Component2" data="Comp2" />
> > <mx:Object label="Component3" data="Comp3" />
> > <mx:Object label="Component4" data="Comp4" />
> > <mx:Object label="Component5" data="Comp5" />
> > </mx:Array>
> > </mx:dataProvider>
> > </mx:ComboBox>
> >
> > <mx:TabBar direction="vertical " dataProvider= "{vsComps} "
> > labelField=" app" y="108" x="27"/>
> >
> > <mx:ViewStack id="vsComps" width="50%" height="50%"
> > x="200" y="108" backgroundColor= "#FFFFC9" >
> >
> > <mx:Canvas id="vView1" label="View1" verticalScrollPolic y="off"
> > horizontalScrollPol icy="off" >
> > <mx:Label x="68" y="2" width="130" text="Initial View --
> > View 1"/>
> > <mx:Label id="lblViewName" x="68" y="32" width="68"
> > text="Input: "/>
> > <mx:TextInput id="txtiInput" x="136" y="32"/>
> > </mx:Canvas>
> > </mx:ViewStack>
> >
> > </mx:Application>
> >
>

 

 

________________________________

Shape Yahoo! in your own image. Join our Network Research Panel today!
<http://us.rd.yahoo.com/evt=48517/*http:/surveylink.yahoo.com/gmrs/yahoo
_panel_invite.asp?a=7>  

 

Reply via email to