Flash 8: attachBitmap

  • Started
  • Last post
  • 6 Responses
  • CyBrain

    I can't get this to work:

    import flash.display.*;
    this.createEmptyMovieClip("bmp1... this.getNextHighestDepth());
    var bmpData1:BitmapData = new BitmapData(980, 280, false, 0xaa3344);
    bmp1.attachBitmap(bmpData1, 2, "auto", true);

    It's verbatim from the Flash help with the exception of the dimensions of my image.

    After publishing Flash 8, AS2, I only get a 980x280 rectangle that hex color(0xaa3344). I have my bitmap image in the library with "bmpData1" in the linkage.

    I assume I'm supposed to do that, but there's no mention of that in the help or in the script.

    My question is how do I get that image in my library to display with this code?

  • rson0

    var linkageId:String = "libraryBitmap";
    var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId...

  • CyBrain0

    Thanks, but I'm still totally in the dark.

    Do I still have to put "libraryBitmap" as the linkage name in my library item (the bitmap)?

    Also, does
    var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId...

    replace my fourth line. If so, shouldn't it read var myBitmapData:new BitmapData = BitmapData.loadBitmap(linkageId...

  • rson0

    What are you trying to do? the idea is that you are loading a graphic bitmap instead of just bitmap data. So you would use it like so ...

    import flash.display.BitmapData;
    import flash.geom.Point;

    var linkageId:String = "libraryBitmap";
    var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId...

    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

    mc.onPress = function() {
    var randomNum:Number = Math.floor(Math.random() * 10);
    dissolve(randomNum);
    }

    var intervalId:Number;
    var totalDissolved:Number = 0;
    var totalPixels:Number = 8000;

    function dissolve(randomNum:Number) {
    var newNum:Number = myBitmapData.pixelDissolve(myBit... myBitmapData.rectangle, new Point(0, 0), randomNum, 40, 0x00FF0000);
    clearInterval(intervalId);
    if(totalDissolved < totalPixels) {
    intervalId = setInterval(dissolve, 10, newNum);
    }
    totalDissolved += 40;
    }

  • rson0

    So yes replace this var bmpData1:BitmapData = new BitmapData(980, 280, false, 0xaa3344); which is just data of a bitmap to this

    var linkageId:String = "libraryBitmap";
    var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId...

    linkageId being the linkage name you create in your lib

  • CyBrain0

    Thanks rson. I was just trying to get the image to display.

    I had some down time at work and did some of my first experimenting with the Bitmap Data Class. It's very confusing at first.

  • rson0

    Cool yeah it is a bit confusion but once you start to think about bitmaps or any graphical image in a more programmatically way it makes more sense.