Zane Clark Zane Clark - 1 month ago 13
ActionScript Question

Bitmap from Library

I looked this up on Google and watched a video, but this doesn't work for me.

When I try to link a symbol in the library with an AS Linkage, then attach it to a BitmapData variable, this error code shows:

Scene 1, Layer 'Layer 1', Frame 1, Line 4 1067: Implicit coercion of a value of type Gun to an unrelated type flash.display:BitmapData.

I don't use bitmap or bitmapdata much, and I don't use classes much, so I have no idea what is wrong. This is my code:

import flash.display.BitmapData;

var gun:BitmapData = new Gun;


And this is my advanced properties for the symbol:

Export for ActionScript = true

Export in frame 1 = true

Class = Gun

(I do not have a file named Gun)

Base Class = flash.display.MovieClip

I do not know what I am doing wrong, because I looked at multiple videos and websites saying that this works.

Can somebody help me? Am I writing the code incorrectly, or is something wrong with my settings?

Answer

You can't declare it as BitmapData - BitmapData is just raw bitmap data :)

Since you have declared MovieClip as Base Class, this should become a MovieClip:

var gun:MovieClip = new Gun();

If your gun has no timeline (so it's a graphics with just one frame), set the Base Class to Sprite and handle it as sprite - this is better for memory and performance:

var gun:Sprite = new Gun();
Comments