I think it depends on the circumstances:

If you are not manipulating the child sprites in any way, just adding them at the start, removing at the end and possibly listening for events on them, why would you want to use more memory by storing the sprite instances in an array or a vector when you already have a storage medium for them - the parent container?

If I was needing to move things around, or juggle the display order, or manipulate sprites in the container, I may want to store a reference to them, but if they are just display elements, it's even simpler just to add them to a container sprite then iterate through the container when you are done with them if you need to remove listeners.

Obviously this is purely down to coding preferences, but why waste arrays, when your DisplayObjectContainer does it for you...

Glen

Merrill, Jason wrote:
I agree with Mr. Tom Rhodes.  Storing references to your "buttons" in an
array is far better than trying to create and use "dynamic" instance
names like "bar"+i.  You can tack on data properties to the buttons as
well, so they have information about themselves that travels with them.


Jason Merrill Bank of America Global Learning Learning & Performance Solutions

Join the Bank of America Flash Platform Community  and visit our
Instructional Technology Design Blog
(note: these are for Bank of America employees only)






-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of tom
rhodes
Sent: Tuesday, February 23, 2010 12:18 PM
To: Flash Coders List
Subject: Re: [Flashcoders] Finding and Removing a Sprite: PART II

ok, bar isn't the name of the sprite, it's a variable with name bar
which
contains a reference to your sprite... if you want to use names then do
something like bar.name = String("bar_" + i); but personally i'd use an
array like so...

var bars:Array = [];

function createBars():void
{
    for (var i:int=0; i<totalbars; i++)
    {
          var bar:Sprite = new Sprite();

             ...............

          addChild(bar);
          bars.push(bar);
    {
}


then you can get at the bars later to do stuff with them or remove
them...

On 23 February 2010 17:55, Lehr, Theodore <ted_l...@federal.dell.com>
wrote:

So here is my next issue... One of the functions creates a dynamic
amount
sprites based on an xml feed, like so


function createBars():void
{
    for (var i:int=0; i<totalbars; i++)
    {
          var bar:Sprite = new Sprite();

             ...............

          addChild(bar);

    {
}

And see this this is where my ears start to bleed... this is seemingly
creating, say, 9 Sprites ALL with the same name "bar".... I need to
keep the
new Sprite() line in the loop for them to be created... but then I
need some
way to access them to delete them....

Any ideas?
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to