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

Reply via email to