1 Reply Latest reply on Aug 7, 2011 6:42 PM by drkstr_1

# Naming rectangles - creating an animation from a sprite sheet

Hello

I am attempting to create an animation from a sprite sheet.

Thanks to the brilliant texture packer (http://www.texturepacker.com/) and a great tutorial by Lee Brimelow (http://gotoandlearn.com/play.php?id=142) I can do this.

I have a list of rectangles like this ...

public static var HappyBirthDay0001:Rectangle = new Rectangle(340,0,340,382);

The solution requires making an array of rectangles something like this:

happyBirthDayRects = [R.HappyBirthDay0001, R.HappyBirthDay0002, R.HappyBirthDay0003, R.HappyBirthDay0004 .....

Which seems inelegant.

Can I create this array on the fly with a loop? Can you help?

I want to do something like this... which obviously isn't code ...

for (var i:int = 0; i < 60; i++)

{

happyBirthDayRects.push("R.HappyBirthDay000" + i);

}

And yes it is a birthday card that has got out of hand.

Thank you very much for any advice

Lizzy

• ###### 1. Re: Naming rectangles - creating an animation from a sprite sheet

Hmm, well I would contend the first option is much better (but that's coming from someone who prefer's strongly typed languages).

I'm not sure if what you're trying to do works with static variables, since I've never actually tried it, but if it did work, it would look something like this...

`happyBirthDayRects.push(R["HappyBirthDay000"+i]);`

Although you would need to add some logic to buffer the zeros correctly for any number larger than 9, which IMHO, is not an elegant solution at all. I actually think this would require more typing than the first solution (if you take autocompletion and copy/paste into account), not to mention the loss of type saftey.