PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
attachBitmap (addChild) dynamically
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: attachBitmap (addChild) dynamically

  1. #1

    attachBitmap (addChild) dynamically

    Hi I am new to AS3, in AS2 it was really easy to select a dynamic attachmovie method

    I'm trying to attach a dynamic bitmap dynamically. In my library I have a load of bitmaps with class export names, img1, img2, img3 etc..

    This works fine

    Actionscript Code:
    var b:img1 = new img1(1020, 696);
    var bm:Bitmap = new Bitmap(b);
    img_mc.addChild(bm);

    But I want to select it dynamically, is there a way of doing this?

    Actionscript Code:
    var dynamicClassName = this["img"+1];
    var b: dynamicClassName = new dynamicClassName(1020, 696);
    var bm:Bitmap = new Bitmap(b);
    img_mc.addChild(bm);

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You can use getDefinitionByName to get a Class by its name.

    But instead of that, you could just put the classes in an array and use that.

    Code:
    var dynamicClass:Class = getDefinitionByName("img"+1);
    var b: BitmapData = new dynamicClass(1020, 696);
    var bm:Bitmap = new Bitmap(b);
    img_mc.addChild(bm);
    Code:
    var imgClasses:Array = [img1, img2, img3];
    var b: BitmapData = new imgClasses[0](1020, 696);
    var bm:Bitmap = new Bitmap(b);
    img_mc.addChild(bm);
    Last edited by 5TonsOfFlax; 05-11-2010 at 02:48 PM.

  3. #3
    Marvelous. Thanks for your quick reply

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