views:

376

answers:

2

Hi,

I just submitted this question but i can't see if it posted anywhere, so I apologize if this is a duplicate.

For a Flash CS4 project, I am constantly importing new images, converting them to movieclips and storing them in the library under an "Ornaments" folder. All of these ornaments need to be on the stage in a certain place when the program is initialized. Instead of having to drag the new symbols onto the stage every time I add a new, is it possible to add all of the symbols in the "Ornament" library folder to the stage at runtime?

Thanks

+1  A: 

You can do it in code if you wish, but you'd have to still add the names of the symbols to the code. That is, the folder is merely a convenience for organizing within the CS4 library and it does not translate to code (AFAIK).

To instantiate the item in AS3, simply right click the symbol in the library and check the box labelled "Export for ActionScript". If you can't see it, click the Advanced button. It will default the Class to the name of the symbol. That will be the class you can instantiate in ActionScript to put an instance on stage.

You could keep an array of the ornament names and loop through them adding them to the stage:

var ornaments:Array = [OrnamentGold, OrnamentSilver, OrnamentBronze];

for each(var ornament:Class in ornaments)
{
    var ornamentClip:MovieClip = new ornament();
    addChild(ornamentClip);
}

If you name all of your instances the same with only a trailing digit incremented, you can save yourself some time and just increment a single number:

const NUM_ORNAMENTS:int = 5;

for(var i:int = 0; i < NUM_ORNAMENTS; i++)
{
    // ornaments are names Ornament0, Ornament1, Ornament2, etc. in the library
    var ornamentClass:Class = new getDefinitionByName("Ornament" + i) as Class;
    var ornamentClip:MovieClip = new ornamentClass();
    addChild(ornamentClip);
}
James Fassett
This looks good. This was what I was going to try. Just wanted to know if there was a way to access the folders through actionscript. Thanks!
Adrian Adkison
This Worked Great!
Adrian Adkison
A: 

This is a test a really good test

Adrian Adkison