-
Loading images from library through a loop
Okay I have much MCs named 'object1','object2','object3',etc...
But for testing and example I will use just 10.
So what I need is attaching an image to its own MC. Images are in library and they are named 's1','s2','s3',etc..
This is how far I got with scripting:
PHP Code:
import flash.utils.getDefinitionByName;
for (var i:uint=1; i<=10;i++) {
var s:String = "s"+i;
//var cr:String = "CR"+i; something is wrong here xS
var cr:Class = getDefinitionByName(s) as Class;
var ss:Bitmap = new Bitmap( new cr(0,0));
var obj:* = "obeject"+i;
obj.addChild(ss);
}
/*
var s1:String = "s"+1;
var ClassReference01:Class = getDefinitionByName(s1) as Class;
var ss1:Bitmap = new Bitmap( new ClassReference01(0,0));
object1.addChild(ss1);*/
Can you help me out?
Thanks.
-
Senior Member
Last edited by realMakc; 05-14-2013 at 03:49 PM.
-
Code:
import flash.utils.getDefinitionByName;
var len:uint = 10;
for (var i:uint=1; i<=len; i++) {
var s:String = "s" + i;
var cr:Class = getDefinitionByName(s) as Class;
var ss:Bitmap = new Bitmap( new cr());
var obj:* = this["object" + i];
obj.addChild(ss);
}
-
Thank you very much dawsonk,It works like a charm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|