It's better to have a parent destroy a child than for a child to destroy
itself. It a child destroys itself, it could be in a weird state during
any code that executes after you call parent.destroyChild(this).

comp2 can call a method in comp1 like this:

    click="parentDocument.deleteRow()"

- Gordon


-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of rgwilson26
Sent: Wednesday, March 08, 2006 6:10 AM
To: [email protected]
Subject: [flexcoders] Re: dynamically destroy child from parent

Thanks, that makes sense. I have one problem though that I can't seem 
to figure out. I am using createChild() in Comp#1 which creates 
comp#2. Comp#2 includes all text inputs including a delete button. Is 
it possible to have that child delete itself, or is it better to have 
the parent delete the child?

If the parent is suppose to delete the child component how do you 
send a reference of the child back to the parent in order to delete 
the correct child instance? 
 *******Comp #1***********
 
 public var rowArray : Object = new Array() ;
 public var counter : Number = 0 ;
       
//----------- Add Row --------------
private function addRow():Void{
rowArray[counter] = comp#2(comp#1.createChild(comp#2, undefined,
{childRow:rowArray}));
counter++;
}

public function deleteRow(event){
if(rowArray[counter] > 0){
destroyChild(rowArray[counter -1]);
counter--;
}
}



******Comp #2***************
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.macromedia.com/2003/mxml"; >
<mx:Script>
<![CDATA[
       import mx.controls.Alert;
       
       public var childRow;
       
 ]]>
 </mx:Script>
                   
             
             <mx:TextArea width="250" height="100" />
             <mx:TextArea width="250" height="100" />
             <mx:TextArea width="250" height="100" />
             <mx:Button label="Delete" click="deleteRow()" /> <--- 
**not sure if it is possible to access the delete function in Comp#1 
to delete this child component**
 </mx:HBox>




--- In [email protected], "Andrew Trice" <[EMAIL PROTECTED]> 
wrote:
>
> You'll need to use the destroyChild function, and pass in a 
reference to
> the object (row) that you want to destroy...
> 
>  
> 
> lessonsLearned.destroyChild(rowArray[indexToDelete]);
> 
>  
> 
> Here's a simple example so you can see how destroyChild works:
> 
>  
> 
> <mx:Effect>
> 
>             <mx:Move name="_move" duration="300"/>
> 
> </mx:Effect>
> 
> <mx:VBox width="50%" height="50%" borderStyle="solid"
> borderThickness="1" id="myVBox">
> 
>  
> 
>             <mx:HBox width="100%">
> 
>                         <mx:Button label="Destroy HBox 1"
> click="myVBox.destroyChild(myHBox_1)" />
> 
>                         <mx:Button label="Destroy HBox 2"
> click="myVBox.destroyChild(myHBox_2)" />
> 
>                         <mx:Button label="Destroy HBox 3"
> click="myVBox.destroyChild(myHBox_3)" />
> 
>             </mx:HBox>
> 
>  
> 
>             <mx:HBox width="100%" borderStyle="solid"
> borderThickness="1" id="myHBox_1" moveEffect="_move">
> 
>                         <mx:Text text="HBox 1" width="100%" />
> 
>             </mx:HBox>
> 
>  
> 
>             <mx:HBox width="100%" borderStyle="solid"
> borderThickness="1" id="myHBox_2" moveEffect="_move">
> 
>                         <mx:Text text="HBox 2" width="100%" />
> 
>             </mx:HBox>
> 
>  
> 
>             <mx:HBox width="100%" borderStyle="solid"
> borderThickness="1" id="myHBox_3" moveEffect="_move">
> 
>                         <mx:Text text="HBox 3" width="100%" />
> 
>             </mx:HBox>
> 
> </mx:VBox>
> 
>  
> 
> -Andy
> 
> _____________________________________
> 
> Andrew Trice
> 
> Cynergy Systems, Inc.
> 
> http://www.cynergysystems.com
> 
>  
> 
> Email: [EMAIL PROTECTED]
> 
> Office: 866-CYNERGY 
> 
>  
> 
> ________________________________
> 
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On
> Behalf Of rgwilson26
> Sent: Tuesday, March 07, 2006 3:47 PM
> To: [email protected]
> Subject: [flexcoders] dynamically destroy child from parent
> 
>  
> 
> I am working on an app where a user can click on a button and 
> dynamically add individual rows (or HBox's) to add multiple 
entries. 
> I have the createchild part working fine, but I am having 
difficulty 
> getting the parent to destroy specific child instances (say the 2nd 
> row instance out of 3). I use createChild() to create an HBox with 
a 
> few inputs and a button. I would like this button to destroy this 
> particular row(or HBox).
> 
> I am assuming it is better to have the parent destroy the child, 
but 
> unsure how exactly to do this. Any suggestions or possibly a better 
> approach?
> 
> Here is what I have so far:
> 
> *******Comp #1***********
> 
> public var rowArray : Object = new Array() ;
> public var counter : Number = 0 ;
>       
> //----------- Add Row --------------
> private function addRow():Void{
> rowArray[counter] = aggregatedRCA.components.lessonsLearnedRow
> (lessonsLearned.createChild
> (aggregatedRCA.components.lessonsLearnedRow, undefined, 
> {rowArray:newRow[counter]}));
> counter++;
> }
> 
> 
> 
> ******Comp #2***************
> <?xml version="1.0" encoding="utf-8"?>
> <mx:HBox xmlns:mx="http://www.macromedia.com/2003/mxml"; >
> <mx:Script>
> <![CDATA[
>       import mx.controls.Alert;
>       
>       public var newRow;
>       
> ]]>
> </mx:Script>
>                   
>             
>             <mx:TextArea width="250" height="100" />
>             <mx:TextArea width="250" height="100" />
>             <mx:TextArea width="250" height="100" />
>             <mx:Button label="Delete" click="" />
> </mx:HBox>
> 
> 
> 
> 
> 
> 
> 
> --
> Flexcoders Mailing List
> FAQ: 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com 
> 
> 
> 
> 
> SPONSORED LINKS 
> 
> Web site design development
> <http://groups.yahoo.com/gads?
t=ms&k=Web+site+design+development&w1=Web+
> 
site+design+development&w2=Computer+software+development&w3=Software+d
es
> 
ign+and+development&w4=Macromedia+flex&w5=Software+development+best+pr
ac
> tice&c=5&s=166&.sig=L-4QTvxB_quFDtMyhrQaHQ>  
> 
> Computer software development
> <http://groups.yahoo.com/gads?
t=ms&k=Computer+software+development&w1=We
> 
b+site+design+development&w2=Computer+software+development&w3=Software
+d
> 
esign+and+development&w4=Macromedia+flex&w5=Software+development+best+
pr
> actice&c=5&s=166&.sig=lvQjSRfQDfWudJSe1lLjHw>  
> 
> Software design and development
> <http://groups.yahoo.com/gads?
t=ms&k=Software+design+and+development&w1=
> 
Web+site+design+development&w2=Computer+software+development&w3=Softwa
re
> 
+design+and+development&w4=Macromedia+flex&w5=Software+development+bes
t+
> practice&c=5&s=166&.sig=1pMBCdo3DsJbuU9AEmO1oQ>  
> 
> Macromedia flex
> <http://groups.yahoo.com/gads?
t=ms&k=Macromedia+flex&w1=Web+site+design+
> 
development&w2=Computer+software+development&w3=Software+design+and+de
ve
> 
lopment&w4=Macromedia+flex&w5=Software+development+best+practice&c=5&s
=1
> 66&.sig=OO6nPIrz7_EpZI36cYzBjw>  
> 
> Software development best practice
> <http://groups.yahoo.com/gads?
t=ms&k=Software+development+best+practice&
> 
w1=Web+site+design+development&w2=Computer+software+development&w3=Sof
tw
> 
are+design+and+development&w4=Macromedia+flex&w5=Software+development+
be
> st+practice&c=5&s=166&.sig=f89quyyulIDsnABLD6IXIw>  
> 
>  
> 
>  
> 
> ________________________________
> 
> YAHOO! GROUPS LINKS 
> 
>  
> 
> *      Visit your group "flexcoders
> <http://groups.yahoo.com/group/flexcoders> " on the web.
>         
> *      To unsubscribe from this group, send an email to:
>        [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]> 
>         
> *      Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/> . 
> 
>  
> 
> ________________________________
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



 




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to