Reputation: 21
Essentially this is what I want to accomplish, however it doesn't work like this. Is there any solution: - The problem is I can't dynamically name a new object... ??? pulling my hair out.
import views.printingView;
public function initComponent(o:Array):void{
SomeObject::Array = o;
for(i=0; i <=SomeObject.length-1; i++){
'invoice'+{SomeObject[i].namedID}:printingView = new printingView();
someDisplayContainer.addChild('invoice'+{SomeObject[i].namedID});
'invoice'+{SomeObject.namedID}.publicInitFunction(SomeObject[i]);
}
}
Upvotes: 1
Views: 500
Reputation: 74899
From the code you posted, there's no need for a dynamically named variable at all. The same code can be simplified to this:
import views.printingView;
public function initComponent(o:Array):void{
for each(var item:Object in o)
{
var v:printingView = new printingView();
someDisplayContainer.addChild(v);
v.publicInitFunction(item);
}
}
If for some reason you really need a dynamically named variable, you can do it like this. This assumes the current object is declared dynamic.
import views.printingView;
public function initComponent(o:Array):void{
SomeObject::Array = o;
for each(var item:Object in o)
{
var name:String = 'invoice' + item.namedID;
this[name] = new printingView();
someDisplayContainer.addChild(this[name]);
this[name].publicInitFunction(item);
}
}
Upvotes: 2