So, are you saying that if you comment out the addEventListener lines you
only end up with one sprite displayed instead of multiple sprites displayed?
That can't be right... what does the code in the event listeners do?
Are you needing a unique ID that ties back to your XML? If so, you first
need a way to uniquely look up the XML elements (by index is fine if the
collection doesn't change, otherwise you'll want to assign an ID attribute
to each element). Then you can use the unique XML element ID's as the "name"
property for your sprite. You can then use the sprite's parent's
getChildByName method to grab the specific sprite.
A more general way to do it: use a dictionary to associate any object with
any other object. In that case, you can use the XML element as the "key" in
the dictionary with the sprite as the "value" (and you can do a reverse
lookup in the same way). In fact, I believe the Dictionary example in the
Flex 2 docs does something very similar.
Troy.
On 6/13/07, jimmedia <[EMAIL PROTECTED]> wrote:
I'm looping through an XML file with the following code
####################################################
for (var i:int = 0; i < numElementsinXML; i++)
{
var sprite:Sprite = new Sprite();
sprite.graphics.lineStyle(0, 0xff0000, 1);
sprite.graphics.beginFill(0xffffff, 1);
sprite.graphics.drawCircle((i+25)*15, 80, 2);
sprite.graphics.endFill();
sprite.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverNode);
sprite.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutNode);
addChild(sprite);
}
####################################################
now the above code without the event listeners displays the proper
number of sprites on the screen with proper spacing (in my case 12
circles). With the event listeners though I only get one sprite
displayed, but it does respond to the MouseEvent.
I want to know how I can loop through my xml and produce a uniquely
named sprite (or in fact object) based on my xml, and be able to
reference it anywhere in my program.
Thanks in advance.