[flexcoders] Re: Adding/Removing child components

2008-05-08 Thread kalpkat9
Thank you all.
...to an extent, the repeater brings the functionality in place. 
here is the code:
?xml version=1.0?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;

mx:Script
![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var ar:ArrayCollection = new ArrayCollection
([{}]); 

public function remove(i:Number):void
{
ar.removeItemAt(i);
}  

public function add():void
{
ar.addItem({});
}

public function calcRowHeight(isHidden:Boolean):Number
{
var retVal:Number=25; 
if(isHidden) 
retVal = 0;
return retVal;
}   

]]
/mx:Script

mx:Grid verticalGap=1
mx:Repeater id=Rep dataProvider={ar}
mx:GridRow id=gridrow height={calcRowHeight
(Rep.currentItem.isHidden)}
mx:GridItem id=griditem 
height={calcRowHeight(Rep.currentItem.isHidden)} 

mx:Button  id=remBtn 
label=Remove click=remove(event.target.repeaterIndices)/
/mx:GridItem
/mx:GridRow   
/mx:Repeater  
/mx:Grid

mx:HBox visible=true horizontalGap=1 height=100% 
width=100%
  mx:HBox height=100% width=100%/
  mx:HBox height=100% width=10%   
mx:LinkButton label=Add click=add()/
  /mx:HBox
/mx:HBox


/mx:Application



--- In flexcoders@yahoogroups.com, Tom Chiverton [EMAIL PROTECTED] 
wrote:

 On Tuesday 06 May 2008, kalpkat9 wrote:
  I dont know where I am missing it, but I am only able to remove 
the
  lines from the bottom of the stack and I wish to remove the line
  items as such with their relevant index.
 
 If you use a Repeater bound to an ArrayCollection of the items, you 
could use 
 ArrayCollection.removeItemAt() and it should Just Work.
 
 -- 
 Tom Chiverton
 Helping to conveniently unleash world-class content
 on: http://thefalken.livejournal.com
 
 
 
 This email is sent for and on behalf of Halliwells LLP.
 
 Halliwells LLP is a limited liability partnership registered in 
England and Wales under registered number OC307980 whose registered 
office address is at Halliwells LLP, 3 Hardman Square, 
Spinningfields, Manchester, M3 3EB.  A list of members is available 
for inspection at the registered office. Any reference to a partner 
in relation to Halliwells LLP means a member of Halliwells LLP.  
Regulated by The Solicitors Regulation Authority.
 
 CONFIDENTIALITY
 
 This email is intended only for the use of the addressee named 
above and may be confidential or legally privileged.  If you are not 
the addressee you must not read it and must not use any information 
contained in nor copy it nor inform any person other than Halliwells 
LLP or the addressee of its existence or contents.  If you have 
received this email in error please delete it and notify Halliwells 
LLP IT Department on 0870 365 2500.
 
 For more information about Halliwells LLP visit www.halliwells.com.





[flexcoders] Re: Adding/Removing child components

2008-05-06 Thread Tim Hoff

Tom and Tracy both have good suggestions.  However, I'd recommend using
any of the List based controls, with an itemRenderer, instead of using a
repeater.  Unlike the Repeater component, which instantiates all objects
that are repeated (no recycling), the List based controls instantiate
only objects visible in the list.

I dont know where I am missing it, but I am only able to remove the
lines from the bottom of the stack

Your problem is with this line:  myAcc.removeChild(vBoxes.pop());.  Here
you are using the array method pop; which always removes the last
element in an array.  While the removeChild method works here, since the
value of the removed array element is returned from pop, this is kind of
a backwards way of controlling the displayList.

There may be some confusion here about collections (data) and the
display list (components).  While you can certainly create an array
and/or arrayCollection of components, it's much easier to create and
maintain a List based control; with an arrayCollection of data bound as
the dataProvider.Then, as Tom indicated, use the built-in
ArrayCollection methods to add/remove the data; and the display
automatically adjusts.  All that you have to do is something like:

myACC.removeItemAt(myList.selectedIndex) ;

-TH

--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote:

 Yes, unless you have some special needs, using Repeater for your
dynamic
 instantiation will save you a lot of work. Plus Repeater supports
 recycleChildren, which will help with performance over creating and
 removing children.

 Tracy

 -Original Message-
 From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
On
 Behalf Of Tom Chiverton
 Sent: Tuesday, May 06, 2008 11:15 AM
 To: flexcoders@yahoogroups.com
 Subject: Re: [flexcoders] Adding/Removing child components

 On Tuesday 06 May 2008, kalpkat9 wrote:
  I dont know where I am missing it, but I am only able to remove the
  lines from the bottom of the stack and I wish to remove the line
  items as such with their relevant index.

 If you use a Repeater bound to an ArrayCollection of the items, you
 could use
 ArrayCollection.removeItemAt() and it should Just Work.

 --
 Tom Chiverton
 Helping to conveniently unleash world-class content
 on: http://thefalken.livejournal.com

 

 This email is sent for and on behalf of Halliwells LLP.

 Halliwells LLP is a limited liability partnership registered in
England
 and Wales under registered number OC307980 whose registered office
 address is at Halliwells LLP, 3 Hardman Square, Spinningfields,
 Manchester, M3 3EB. A list of members is available for inspection at
 the registered office. Any reference to a partner in relation to
 Halliwells LLP means a member of Halliwells LLP. Regulated by The
 Solicitors Regulation Authority.

 CONFIDENTIALITY

 This email is intended only for the use of the addressee named above
and
 may be confidential or legally privileged. If you are not the
addressee
 you must not read it and must not use any information contained in nor
 copy it nor inform any person other than Halliwells LLP or the
addressee
 of its existence or contents. If you have received this email in error
 please delete it and notify Halliwells LLP IT Department on 0870 365
 2500.

 For more information about Halliwells LLP visit www.halliwells.com.

 

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





[flexcoders] Re: Adding/Removing child components

2008-05-06 Thread Tim Hoff

Wanted to clarify that when I say (no recycling), I'm refering to
itemRenderer reuse with the same set of data.  The recycleChildren
property of a Rpeater does allow for the re-use of children; when a new
data is used.

-TH

In flexcoders@yahoogroups.com, Tim Hoff [EMAIL PROTECTED] wrote:


 Tom and Tracy both have good suggestions. However, I'd recommend using
 any of the List based controls, with an itemRenderer, instead of using
a
 repeater. Unlike the Repeater component, which instantiates all
objects
 that are repeated (no recycling), the List based controls instantiate
 only objects visible in the list.

 I dont know where I am missing it, but I am only able to remove the
 lines from the bottom of the stack

 Your problem is with this line: myAcc.removeChild(vBoxes.pop());. Here
 you are using the array method pop; which always removes the last
 element in an array. While the removeChild method works here, since
the
 value of the removed array element is returned from pop, this is kind
of
 a backwards way of controlling the displayList.

 There may be some confusion here about collections (data) and the
 display list (components). While you can certainly create an array
 and/or arrayCollection of components, it's much easier to create and
 maintain a List based control; with an arrayCollection of data bound
as
 the dataProvider. Then, as Tom indicated, use the built-in
 ArrayCollection methods to add/remove the data; and the display
 automatically adjusts. All that you have to do is something like:

 myACC.removeItemAt(myList.selectedIndex) ;

 -TH

 --- In flexcoders@yahoogroups.com, Tracy Spratt tspratt@ wrote:
 
  Yes, unless you have some special needs, using Repeater for your
 dynamic
  instantiation will save you a lot of work. Plus Repeater supports
  recycleChildren, which will help with performance over creating and
  removing children.
 
  Tracy
 
  -Original Message-
  From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
 On
  Behalf Of Tom Chiverton
  Sent: Tuesday, May 06, 2008 11:15 AM
  To: flexcoders@yahoogroups.com
  Subject: Re: [flexcoders] Adding/Removing child components
 
  On Tuesday 06 May 2008, kalpkat9 wrote:
   I dont know where I am missing it, but I am only able to remove
the
   lines from the bottom of the stack and I wish to remove the line
   items as such with their relevant index.
 
  If you use a Repeater bound to an ArrayCollection of the items, you
  could use
  ArrayCollection.removeItemAt() and it should Just Work.
 
  --
  Tom Chiverton
  Helping to conveniently unleash world-class content
  on: http://thefalken.livejournal.com
 
  
 
  This email is sent for and on behalf of Halliwells LLP.
 
  Halliwells LLP is a limited liability partnership registered in
 England
  and Wales under registered number OC307980 whose registered office
  address is at Halliwells LLP, 3 Hardman Square, Spinningfields,
  Manchester, M3 3EB. A list of members is available for inspection at
  the registered office. Any reference to a partner in relation to
  Halliwells LLP means a member of Halliwells LLP. Regulated by The
  Solicitors Regulation Authority.
 
  CONFIDENTIALITY
 
  This email is intended only for the use of the addressee named above
 and
  may be confidential or legally privileged. If you are not the
 addressee
  you must not read it and must not use any information contained in
nor
  copy it nor inform any person other than Halliwells LLP or the
 addressee
  of its existence or contents. If you have received this email in
error
  please delete it and notify Halliwells LLP IT Department on 0870 365
  2500.
 
  For more information about Halliwells LLP visit www.halliwells.com.
 
  
 
  --
  Flexcoders Mailing List
  FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
  Search Archives:
  http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo!
Groups
  Links
 






[flexcoders] Re: Adding/Removing child components

2008-05-06 Thread Amy
--- In flexcoders@yahoogroups.com, Tim Hoff [EMAIL PROTECTED] wrote:

 
 Tom and Tracy both have good suggestions.  However, I'd recommend 
using
 any of the List based controls, with an itemRenderer, instead of 
using a
 repeater.  Unlike the Repeater component, which instantiates all 
objects
 that are repeated (no recycling), the List based controls instantiate
 only objects visible in the list.

However, if you know that the most likely use case is that the repeater 
will not be showing enough items to cause scrolling, you may want to 
consider this:

http://flexdiary.blogspot.com/2008/04/is-horizontallist-faster-than-
hbox-with.html





[flexcoders] Re: Adding/Removing child components

2008-05-06 Thread Tim Hoff

Absolutely Amy,

Or if you know that the number items will always be performance
acceptable, put your list in a container and set the height of the list
to measuredHeightOfItems; to ensure smooth scrolling by instantiating
all of the items like a repeater.  No right or wrong; just depends.

-TH

--- In flexcoders@yahoogroups.com, Amy [EMAIL PROTECTED] wrote:

 --- In flexcoders@yahoogroups.com, Tim Hoff TimHoff@ wrote:
 
 
  Tom and Tracy both have good suggestions. However, I'd recommend
 using
  any of the List based controls, with an itemRenderer, instead of
 using a
  repeater. Unlike the Repeater component, which instantiates all
 objects
  that are repeated (no recycling), the List based controls
instantiate
  only objects visible in the list.

 However, if you know that the most likely use case is that the
repeater
 will not be showing enough items to cause scrolling, you may want to
 consider this:

 http://flexdiary.blogspot.com/2008/04/is-horizontallist-faster-than-
 hbox-with.html