warpstack
warpstack

Reputation: 71

AS3: using beginBitmapFill() with a library object

How can I setup a .beginBitmapFill() with a bitmap loaded into the movie's library? Every example I've found on the internet uses the loader class to load the bitmap externally, but I want to load it from the library instead.

I want to turn:

mesh.graphics.beginFill(0xFFFFFF,1);

into

mesh.graphics.beginBitmapFill(..., null, true, false);

and have my shape filled with a tiled 'bitmap.bmp' loaded into the library. The major problem is how I can address the library bitmap inside the fill method.

Upvotes: 1

Views: 7071

Answers (1)

Chunky Chunk
Chunky Chunk

Reputation: 17237

add the image file to your library and export it to ActionScript as a BitmapData object:

enter image description here

then you can write the graphics code like this:

import flash.display.BitmapData;
import flash.display.Shape;

var mesh:Shape = new Shape();
mesh.graphics.beginBitmapFill(new MeshBitmapData(), null, true, false);
mesh.graphics.drawRect(0, 0, 400, 400);
mesh.graphics.endFill();

mesh.x = mesh.y = 20;

addChild(mesh);

and you will get this:

enter image description here

Upvotes: 9

Related Questions