RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Lehr, Theodore
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; itotalbars; 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


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Keith Reinfeld
You could parent them. 

Var barMom:Sprite = new Sprite();
addChild(barMom);
function createBars():void
{
 for (var i:int=0; itotalbars; i++)
 {
   var bar:Sprite = new Sprite();
bar.name = barBrat+i;
  ...

   barMom.addChild(bar);

 {
}

This way at least you know where they live. 


Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net

 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-
 boun...@chattyfig.figleaf.com] On Behalf Of Lehr, Theodore
 Sent: Tuesday, February 23, 2010 10:55 AM
 To: Flash Coders List
 Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II
 
 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; itotalbars; 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
 No virus found in this incoming message.
 Checked by AVG - www.avg.com
 Version: 9.0.733 / Virus Database: 271.1.1/2705 - Release Date:
 02/23/10 01:34:00

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


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Glen Pike

bar.name = bar_ + i;



function destroyBars():void {
   for (var i:int=0; itotalbars; i++)
   {
 var bar:Sprite = getChildByName(bar_ +i) as Sprite;
 if(bar) {
...
removeChild(bar);
 }
}
}

Lehr, Theodore 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; itotalbars; 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


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Lehr, Theodore
Thanks man - that did it


From: flashcoders-boun...@chattyfig.figleaf.com 
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Keith Reinfeld 
[keithreinf...@comcast.net]
Sent: Tuesday, February 23, 2010 12:10 PM
To: 'Flash Coders List'
Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II

You could parent them.

Var barMom:Sprite = new Sprite();
addChild(barMom);
function createBars():void
{
 for (var i:int=0; itotalbars; i++)
 {
   var bar:Sprite = new Sprite();
bar.name = barBrat+i;
  ...

   barMom.addChild(bar);

 {
}

This way at least you know where they live.


Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net

 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-
 boun...@chattyfig.figleaf.com] On Behalf Of Lehr, Theodore
 Sent: Tuesday, February 23, 2010 10:55 AM
 To: Flash Coders List
 Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II

 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; itotalbars; 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
 No virus found in this incoming message.
 Checked by AVG - www.avg.com
 Version: 9.0.733 / Virus Database: 271.1.1/2705 - Release Date:
 02/23/10 01:34:00

___
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


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread tom rhodes
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; itotalbars; 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; itotalbars; 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


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Henrik Andersson

Lehr, Theodore wrote:

Any ideas?


Store a reference to each object in a vector like this:

var bars:Vector.Bar=new Vector.Bar();
function createBars():void {
for (var i:int=0; itotalbars; i++) {
var bar:Bar = new Bar();
...
addChild(bar);
bars.push(bar);
}
}
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Geografiek

You could create an empty array (outside the functions)
And add each newly created bar to the array.
Afterwards, say in another function, you can reference the array  
indexes.

Something like:

myBarsArray = new Array();
function createBars():void
{
 for (var i:int=0; itotalbars; i++)
 {
   var bar:Sprite = new Sprite();
  ...
   addChild(bar);
   myBarsArray.push(bar);
 {
}
function removeBars(i:uint):void
{
 removeChild(myBarsArray[i]);
 //don't remove the bar from the array
}
HTH,
Willem

On 23-feb-2010, at 17:55, Lehr, Theodore 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; itotalbars; 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




=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Geografiek is a Dutch, Utrecht-based map and chart design company.
Willem van den Goorbergh can be contacted by telephone: (+31) 
30-2719512 or cell phone: (+31)6-26372378

or by fax: (+31)302719687
snail mail: Hooghiemstraplein 89 3514 AX UTRECHT
Visit our website at: http://www.geografiek.nl
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=




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


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Nathan Mynarcik
Inside your loop, you can add the sprite to a movieclip and give each movieclip 
a name using the variable in your loop like:

mcName.name = mc+i; //or whatever your for loop var is

And then remove it by getChildByName(mc#);


--Original Message--
From: Lehr, Theodore
Sender: flashcoders-boun...@chattyfig.figleaf.com
To: Flash Coders List
ReplyTo: Flash Coders List
Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II
Sent: Feb 23, 2010 10:55 AM

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


Nathan Mynarcik
Interactive Web Developer
nat...@mynarcik.com
254.749.2525
www.mynarcik.com

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


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Lehr, Theodore
A peculair twist now is that these bar sprites are being sent to the back 
(meaning I have other sprites - lines) showing on top when they were and should 
showing in the back... imagine if you will a bar chart - that has horizontal 
lines in the back... these lines now show on top of the bars... anyway to force 
them to be on the bottom layer?


From: flashcoders-boun...@chattyfig.figleaf.com 
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Keith Reinfeld 
[keithreinf...@comcast.net]
Sent: Tuesday, February 23, 2010 12:10 PM
To: 'Flash Coders List'
Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II

You could parent them.

Var barMom:Sprite = new Sprite();
addChild(barMom);
function createBars():void
{
 for (var i:int=0; itotalbars; i++)
 {
   var bar:Sprite = new Sprite();
bar.name = barBrat+i;
  ...

   barMom.addChild(bar);

 {
}

This way at least you know where they live.


Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net

 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-
 boun...@chattyfig.figleaf.com] On Behalf Of Lehr, Theodore
 Sent: Tuesday, February 23, 2010 10:55 AM
 To: Flash Coders List
 Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II

 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; itotalbars; 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
 No virus found in this incoming message.
 Checked by AVG - www.avg.com
 Version: 9.0.733 / Virus Database: 271.1.1/2705 - Release Date:
 02/23/10 01:34:00

___
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


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Merrill, Jason
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; itotalbars; 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; itotalbars; 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


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Glen Pike

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


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Keith Reinfeld
addChildAt(child:DisplayObject, index:int) 

So: 

this.addChildAt(barMom, 0);

Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net


 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-
 boun...@chattyfig.figleaf.com] On Behalf Of Lehr, Theodore
 Sent: Tuesday, February 23, 2010 11:29 AM
 To: Flash Coders List
 Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II
 
 A peculair twist now is that these bar sprites are being sent to the
 back (meaning I have other sprites - lines) showing on top when they
 were and should showing in the back... imagine if you will a bar chart
 - that has horizontal lines in the back... these lines now show on top
 of the bars... anyway to force them to be on the bottom layer?
 
 
 From: flashcoders-boun...@chattyfig.figleaf.com [flashcoders-
 boun...@chattyfig.figleaf.com] On Behalf Of Keith Reinfeld
 [keithreinf...@comcast.net]
 Sent: Tuesday, February 23, 2010 12:10 PM
 To: 'Flash Coders List'
 Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II
 
 You could parent them.
 
 Var barMom:Sprite = new Sprite();
 addChild(barMom);
 function createBars():void
 {
  for (var i:int=0; itotalbars; i++)
  {
var bar:Sprite = new Sprite();
 bar.name = barBrat+i;
   ...
 
barMom.addChild(bar);
 
  {
 }
 
 This way at least you know where they live.
 
 
 Regards,
 
 Keith Reinfeld
 Home Page: http://keithreinfeld.home.comcast.net
 
  -Original Message-
  From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-
  boun...@chattyfig.figleaf.com] On Behalf Of Lehr, Theodore
  Sent: Tuesday, February 23, 2010 10:55 AM
  To: Flash Coders List
  Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II
 
  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; itotalbars; 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
  No virus found in this incoming message.
  Checked by AVG - www.avg.com
  Version: 9.0.733 / Virus Database: 271.1.1/2705 - Release Date:
  02/23/10 01:34:00
 
 ___
 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
 No virus found in this incoming message.
 Checked by AVG - www.avg.com
 Version: 9.0.733 / Virus Database: 271.1.1/2705 - Release Date:
 02/23/10 01:34:00

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


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Nathan Mynarcik
You can use the addChildAt method and tell it where to add the object in the 
displaylist. 

addChildAt(objectName, 0); will add the objectName to the bottom of the display 
list. 


Nathan Mynarcik
Interactive Web Developer
nat...@mynarcik.com
254.749.2525
www.mynarcik.com

-Original Message-
From: Lehr, Theodore ted_l...@federal.dell.com
Date: Tue, 23 Feb 2010 12:28:39 
To: Flash Coders Listflashcoders@chattyfig.figleaf.com
Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II

A peculair twist now is that these bar sprites are being sent to the back 
(meaning I have other sprites - lines) showing on top when they were and should 
showing in the back... imagine if you will a bar chart - that has horizontal 
lines in the back... these lines now show on top of the bars... anyway to force 
them to be on the bottom layer?


From: flashcoders-boun...@chattyfig.figleaf.com 
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Keith Reinfeld 
[keithreinf...@comcast.net]
Sent: Tuesday, February 23, 2010 12:10 PM
To: 'Flash Coders List'
Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II

You could parent them.

Var barMom:Sprite = new Sprite();
addChild(barMom);
function createBars():void
{
 for (var i:int=0; itotalbars; i++)
 {
   var bar:Sprite = new Sprite();
bar.name = barBrat+i;
  ...

   barMom.addChild(bar);

 {
}

This way at least you know where they live.


Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net

 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-
 boun...@chattyfig.figleaf.com] On Behalf Of Lehr, Theodore
 Sent: Tuesday, February 23, 2010 10:55 AM
 To: Flash Coders List
 Subject: RE: [Flashcoders] Finding and Removing a Sprite: PART II

 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; itotalbars; 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
 No virus found in this incoming message.
 Checked by AVG - www.avg.com
 Version: 9.0.733 / Virus Database: 271.1.1/2705 - Release Date:
 02/23/10 01:34:00

___
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


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Merrill, Jason
IMO, an array is hardly a waste of space, and allows for expanding your
app easier if need be, but you're right, could come down to coding
preferences in that case.  More often though I think, the benefits of
storing them in an array outweigh the benefits of dynamic naming.


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 Glen
Pike
Sent: Tuesday, February 23, 2010 12:43 PM
To: Flash Coders List
Subject: Re: [Flashcoders] Finding and Removing a Sprite: PART II

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; itotalbars; 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; itotalbars; 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
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Mark Winterhalder
On Tue, Feb 23, 2010 at 6:43 PM, Glen Pike g...@engineeredarts.co.uk wrote:
 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?

We're talking about only nine instances here. It would be a different
matter if it were tens or hundreds of thousands, but even then the
additional memory required to store another reference to them would be
insignificant compared to the memory the Sprites themselves would use,
and performance would be the far bigger issue.

So, a descriptively named collection has a higher benefit, for
readability alone. Preferably a Vector, so casting isn't necessary
even when the Sprites for the bars become a proper Bar class, as they
probably should.

I'd still put them in their own container, though. Then the container
goes on top of another with the lines.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Keith Reinfeld
More than one way to get things done. Depends on your needs. Check out
DisplayObjectContainer in the docs. 
 
var barMom:Sprite = new Sprite(); 
this.addChildAt(barMom, 0); 
function createBars():void { 
for (var i:int=0; i  9; i++) { 
var bar:Sprite = new Sprite(); 
bar.name = barBrat + i; 
barMom.addChild(bar); 
} 
} 
 
function spankABrat(container:Sprite, childName:String):void{ 
container.removeChild(container.getChildByName(childName)); 
} 

function eightySixBrats(container:Sprite):void { 
var len:uint = container.numChildren; 
for (var i:uint = 0; i  len; i++) { 
container.removeChildAt(0); 
} 
} 
 
trace(barMom.numChildren =,barMom.numChildren);// 0 
createBars(); 
trace(barMom.numChildren =,barMom.numChildren);// 9 
spankABrat(barMom, barBrat3); 
trace(barMom.numChildren =,barMom.numChildren);// 8 
eightySixBrats(barMom); 
trace(barMom.numChildren =,barMom.numChildren);// 0 
 
Jason: 
Doesn't storing them in an array create a set of references that will need
to be cleaned up? 
 
Regards,

Keith Reinfeld
Home Page: http://keithreinfeld.home.comcast.net



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


RE: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread Merrill, Jason
 Doesn't storing them in an array create a set of references that will
need
to be cleaned up?

Absolutely (if the app performance even needs cleaning up and/or the
items are even removed).  But that's easily taken care of with a cleanup
function.  So for small uses, as I mentioned, may not be worthwhile, but
I am thinking long term scalability.  I just hate to see people default
to dynamic naming all the time when architecturally, using arrays as
storage is better in the long run.  For this, the dynamic naming would
be fine.  I'd just be careful to make it a habit for everything.  


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)



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


Re: [Flashcoders] Finding and Removing a Sprite: PART II

2010-02-23 Thread tom rhodes
yeah, horses for courses...

if you want to better encapsulate stuff, i find it easier to work with
arrays (in fp10 vectors) and pass them around if needs be. tying your code
to specific timelines gives you more work to do if you want to reuse that
code imho.

for something quick and dirty in timeline code though that you know you
don't want to reuse then whatever's clever. Mr. Jason Merrill is right
though about having cleanup functions for whatever you create being a great
way to not getting into trouble later i reckon...


On 23 February 2010 20:47, Merrill, Jason
jason.merr...@bankofamerica.comwrote:

  Doesn't storing them in an array create a set of references that will
 need
 to be cleaned up?

 Absolutely (if the app performance even needs cleaning up and/or the
 items are even removed).  But that's easily taken care of with a cleanup
 function.  So for small uses, as I mentioned, may not be worthwhile, but
 I am thinking long term scalability.  I just hate to see people default
 to dynamic naming all the time when architecturally, using arrays as
 storage is better in the long run.  For this, the dynamic naming would
 be fine.  I'd just be careful to make it a habit for everything.


 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)



 ___
 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