Question

I'm trying to embed an x number of symbols with this:

[Embed(source='graphics/backgrounds.swf', symbol='background01')]
private var Background01 : Class;

the problem is that i have like 100 background symbols and would like to embed them without writing every single one like the code below here:

[Embed(source='graphics/backgrounds.swf', symbol='background01')]
private var Background01 : Class;

[Embed(source='graphics/backgrounds.swf', symbol='background02')]
private var Background02 : Class;

[Embed(source='graphics/backgrounds.swf', symbol='background03')]
private var Background03 : Class;

instead i would like to use 2 loops like this:

for (var i = 0;i < 10;i++)
{
    for (var j = 0;j < 10;j++)
    {
        [Embed(source='graphics/backgrounds.swf', symbol='background' + i + j )]
        // code for adding this to an 2d-array or something
    }
}

this wont work because it tells me that the meta data is wrong so my question is:

Is it possible to do this? or is there a similar way to do this?

Was it helpful?

Solution

Yeah, sad to say Marcus, there's no way of doing what you're trying. MetaData is not AS3, it is not evaluated, so you can't use it the way that you are trying.

If however, you're going to embed the 100 background symbols anyway, why not create a single MovieClip with each one on a frame in the timeline? Then embed that symbol once and use gotoAndStop to go to the one you want?

100 backgrounds all loaded into memory at the start sounds like a dodgy way to go to me in general though. Better would probably be to load backgrounds in and out of memory as and when you need them. It depends what they are used for of course, but the name 'background' suggests to me that this might be a better course of action.

OTHER TIPS

I don't believe you can put meta directives in regular code statements. They're part of the declaration of a variable in the scope of the class you're writing.

If writing so many variables proves onerous, and you have named the symbols sequentially as you have, write a javascript macro in your favorite text editor (I use and love ActiveState's KomodoEdit, and it's free) and have it spit out the text you can paste into your class ActionScript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top