A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: CS4 or CS5 AS3 Loading images from library referenced in an array

  1. #1
    Member
    Join Date
    Nov 2004
    Posts
    39

    CS4 or CS5 AS3 Loading images from library referenced in an array

    I have 28 jpegs in my library. I want to call them as needed from an array.

    This code works fine for 1 image.

    Code:
    var myPic:Bitmap = new Bitmap(new pic1);
    var scaleFactor:Number = 0.35;
    var newWidth:Number = myPic.width * scaleFactor;
    var newHeight:Number = myPic.height * scaleFactor;
    var scaledBitmapData:BitmapData = new BitmapData(newWidth,newHeight,true,0xFFFFFFFF);
    var scaleMatrix:Matrix=new Matrix();
    scaleMatrix.scale(scaleFactor,scaleFactor);
    scaledBitmapData.draw(myPic,scaleMatrix);
    myPic.bitmapData = scaledBitmapData;
    pic_holder.addChild(myPic);
    When I try to replace the first line with an array reference like this...

    Code:
    var myPic:Bitmap = new Bitmap(new myArray[0][8]);
    I get this error....

    TypeError: Error #1007: Instantiation attempted on a non-constructor.

    How can I easily reference the picture from my array. I have 28 arrays nested in another array. Each nested array contains strings, a sound and a jpeg

    Thanks.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    new myArray[0][8] is a non-constructor. Also you need to reference to BitmapData. Use a Vector for the BitmapData instead of an array:

    var myBitmaps:Vector.<BitmapData> = new Vector.<BitmapData>;
    myBitmaps.push(bmc1);//bmc1 is a BitmapData variable.
    myBitmaps.push(bmc2);
    myBitmaps.push(bmc3);
    var myArray:Array = new Array();
    myArray.push(myBitmaps);
    var myPic:Bitmap = new Bitmap(myArray[0][1]);
    - The right of the People to create Flash movies shall not be infringed. -

Tags for this Thread

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