A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Loading images from library through a loop

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    22

    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=1i<=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.

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    921
    error message?
    Last edited by realMakc; 05-14-2013 at 03:49 PM.
    who is this? a word of friendly advice: FFS stop using AS2

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518
    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);
    }

  4. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    22
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center