Chunky Chunk
Chunky Chunk

Reputation: 17217

ActionScript - BeginBitmapFill With BitmapData Library Asset?

I've imported an image asset (Background.jpg) to my Flash CS5 library and exported it to ActionScript as class Bitmap with a base type of BitmapData.

the following code returns the following error:

backgroundTexture = new Shape();
backgroundTexture.graphics.beginBitmapFill(Background);
backgroundTexture.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
backgroundTexture.graphics.endFill();

1067: Implicit coercion of a value of type Class to an unrelated type flash.display:BitmapData.

enter image description here

so what's the error?

Upvotes: 0

Views: 2333

Answers (2)

zzzzBov
zzzzBov

Reputation: 179046

You just need an instance of the Background BitmapData object:

backgroundTexture.graphics.beginBitmapFill(new Background());

Background is a reference to the class. new Background() creates an instance of the class.

Upvotes: 1

Michael Brewer-Davis
Michael Brewer-Davis

Reputation: 14276

I have more experience with Flex than Flash, so I don't know the UI details, but I believe what you want is:

var background:BitmapAsset = new Background() as BitmapAsset;
backgroundTexture.graphics.beginBitmapFill(background.bitmapData);

This is assuming that your UI generates the following ActionScript or its equivalent:

[Embed(source="Background.jpg")]
public var Background:Class;

See:

Upvotes: 1

Related Questions