Thanks Matt, that worked great! However, I am creating a new 
component with my add function. That component is an HBox with 
various text inputs and a delete button to handle a delete function 
for that particular HBox. How do I get the newly created component to 
recognize what number it is in the array and to delete itself? Do I 
need to dispatch the position in the array from the first component, 
handle it in the 2nd component, call a delete function then dispatch 
that result back to the 1st component? Or, is there a better way to 
get this functionality?


***********
comp1:
***********
 <?xml version="1.0"?> 
<mx:Form xmlns:mx="http://www.macromedia.com/2003/mxml"; >
 
 <mx:Script>
 <![CDATA[
        var rowArray : Object = new Array() ;
        var counter : Number = 0 ;
                        
        
 private function addRow():Void
 {
 rowArray[counter] = comp2(HBox.createChild(comp2));
 counter++;
                }
                
 public function deleteRow():Void{  //<-- this function does not work
 
 if(rowArray[counter] > 0){
 this.destroyChild(rowArray[counter -1] );
 counter--;
 }
 }
        
 ]]>
 </mx:Script>

 <mx:Button label="Add" width="60" click="addRow();"/>
 
 <mx:FormItem textAlign="left" id="formItem">
 <mx:HBox>
 <mx:TextInput id="txtRCAParticipants" width="150"/>
 <mx:TextInput id="txtTitle" width="150"/               
 
 <mx:Button label="Delete" click="deleteRow();" />
 </mx:HBox>
 </mx:FormItem>
 </mx:Form>

***********
comp2: <--- component being created from add function
***********
public function deleteMe(){
  //delete this object instance in the array 
}



<mx:HBox height="25" xmlns:mx="http://www.macromedia.com/2003/mxml"; 
xmlns="*">
<mx:TextInput id="txtRCAParticipants1" width="150" text="" />
<mx:TextInput id="txtPhoneNumber1" width="150" text="" />
<mx:Spacer width="20" />
<mx:Button label="Delete" click="deleteMe()"  textAlign="center" />
</mx:HBox>





--- In [email protected], "Matt Chotin" <[EMAIL PROTECTED]> wrote:
>
> I think that if statement should be
> 
> if (counter > 0)
> {
>   this.destroyChild(rowArray[counter-1]);
>   counter--;
> }
> 
> Matt
> 
> -----Original Message-----
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On
> Behalf Of rgwilson26
> Sent: Tuesday, February 21, 2006 8:56 AM
> To: [email protected]
> Subject: [flexcoders] createChild and destroyChild
> 
> I am new to FLEX and am working on an app that allows the user to 
> dynamically create a FormItem w/ various text boxes dynamically 
from 
> a click event including a delete button in each form item that will 
> allow the user to delete that specific instance of the object. I am 
> able to create the FormItem using createChild, but don't know how 
to 
> get destroyChild to work for a specific object. I am guessing you 
> must reference "this" when referring to the specific FormItem 
object, 
> but not sure of the correct syntax.
> 
> Note: In my code my add function calls a component I have created 
> (Start_New_Event.Components.Entry) 
> 
> 
> Here is what I have:
> ***********************
> Main.mxml
> **********************
> <?xml version="1.0"?> 
> <mx:Form xmlns:mx="http://www.macromedia.com/2003/mxml"; >
> 
> <mx:Script>
> <![CDATA[
>       var rowArray : Object = new Array() ;
>       var counter : Number = 0 ;
>                       
>       
> private function addRow():Void
> {
> rowArray[counter] = Start_New_Event.Components.Entry
> (formItem.createChild(Start_New_Event.Components.Entry, undefined, 
> null ) );
> counter++;
>               }
>               
> public function deleteRow():Void{  //<-- this function does not work
> 
> if(rowArray[counter] != 0){
> this.destroyChild(rowArray[counter -1] );
> counter--;
> }
> }
>       
> ]]>
> </mx:Script>
>
> <mx:Button label="Add" width="60" click="addRow();"/>
> 
> <mx:FormItem textAlign="left" id="formItem">
> <mx:HBox>
> <mx:TextInput id="txtRCAParticipants" width="150"/>
> <mx:TextInput id="txtTitle" width="150"/              
> 
> <mx:Button label="Delete" click="deleteRow();" />
> </mx:HBox>
> </mx:FormItem>
> </mx:Form>

> 
> 
> 
> 
> 
> --
> 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