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:
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.
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:
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:
**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.