# Dynamically placing movieclips on the stage

**URL:** <https://forum.kirupa.com/t/dynamically-placing-movieclips-on-the-stage/332679>\
**Category:** Uncategorized\
**Created:** [September 26, 2014, 12:52pm UTC](https://forum.kirupa.com/t/dynamically-placing-movieclips-on-the-stage/332679 "2014-09-26T12:52:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChiefNinja2](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@ChiefNinja2](https://forum.kirupa.com/u/ChiefNinja2)\
**Post date:** [September 26, 2014, 12:52pm UTC](https://forum.kirupa.com/t/dynamically-placing-movieclips-on-the-stage/332679/1 "2014-09-26T12:52:53Z")

</div>

Right, I’m pretty new to AS3, so I don’t know how difficult this will be to solve, but here goes.

At the moment, I’m dynamically loading in stuff from text files. Here is part of the text file:

```auto

workRolesString=role_creative_direction role_concept_art role_modelling role_texturing role_rigging role_animation role_lighting role_rendering role_compositing role_editing

```

Once this is brought into flash I turn it from a string into an array using.

```auto

var workRolesArray:Array = workRolesString.split(" ");

```

So now I have an array, I know this works because I used trace() and it looks fine.  
I have a bunch of movieclips in the library, exported for actionscript and given classnames and stuff. The idea is that I loop through the array, then place icons based on the values. So, for example, there is a movieclip with an ‘as linkage’ of ‘role\_rendering’ and if the array contains this value, the icon is placed. Here is the code I’ve got so far:

```auto

function onWork001Loaded(e:Event):void {

    workTitle.text = e.target.data.workTitle;
    workDescription.text = e.target.data.workDesc;
    workLength.text = e.target.data.workLength;
    var workRolesString:String = e.target.data.workRolesString;
    
        // split the data by words, to end up with an array of entries
        var workRolesArray:Array = workRolesString.split(" ");
        
        for (var index in workRolesArray) 
        {
            var workRoleString:String = workRolesArray[index]
            var workRoleClass:Class = getDefinitionByName(workRoleString) as Class;
            
            trace(index + " => " + workRoleString);
            
            var workRoleInstance:workRoleClass = new workRoleClass(); 
            icon_container.addChild(workRoleInstance);
            workRoleInstance.x=index*42;               
        }

}

```

So the first problem is that I get an error on compiling, which states ‘Type was not found or was not a compile-time constant: workRoleClass.’

If I replace workRoleClass with the actual as linkage of one of the symbols, like so:

```auto

            **var workRoleInstance:role_dummy = new role_dummy();**
            icon_container.addChild(workRoleInstance);
            workRoleInstance.x=index*42;               
        }

```

The compile error disappears, but I get an error in the output panel which says ‘Error #1065: Variable role\_creative\_direction is not defined.’ Some people seem to be saying that this is something to do with instantiating classes…

My situation is possibly made even more complex since I am not just adding these icons to the stage, I am adding them to a nested movieclip.

Sorry for the wall of text, but I wanted to explain it properly. I don’t _really_ know what I’m doing either, so if possible, try to explain things simply.
