Reputation: 131
I'm sort of new to Flash. I understand it's nearly obsolete, but the project I'm working on is written in Flash.
My current task is to obtain RGB data from any pixel in a .jpg file. I have done the following so far:
I have saved the image as a .fla file, and converted the image itself into its own custom class, called "StageWheel", with BitmapData as its base class. However, when I do this:
var sWheel:StageWheel = new StageWheel();
addChild(sWheel);
sWheel.addEventListener(MouseEvent.CLICK, getColorSample);
var bitmapWheel:BitmapData = new BitmapData(sWheel.width, sWheel.height);
I get an error:
"Implicit coercion of a value of type StageWheel to an unrelated type flash.display.DisplayObject"
on the line with
addChild(sWheel);
What does this error mean? Can I not use addChild to add things to the stage this way?
EDIT
That worked @LDMS, thank you. I am now trying to do this later on:
var rgb:uint = bitMapWheel.getPixel(sWheel.mouseX,sWheel.mouseY);
and get an error
"1061: Call to a possibly undefined method getPixel through a reference with static type flash.display:Bitmap."
What does this mean? Can I not use getPixel on a Bitmap? Sorry for the newbiness, for some reason Flash is extremely difficult for me to learn.
Upvotes: 0
Views: 76
Reputation: 14406
Your StageWheel
class is BitmapData, which is not itself a display object that can be added to the stage.
You need to wrap your bitmap data into a Bitmap
to make it a display object.
var sWheel:BitmapData = new StageWheel(); //This is bitmap data, which is not a display object, just data at this point.
//to display the bitmap data, you need to create a bitmap and tell that bitmap to use the bitmap data
var bitmapWheel:Bitmap = new Bitmap(sWheel);
//now you can add the bitmap to the display list
addChild(bitmapWheel);
EDIT
For the second part of your question, you need to acess the bitmap data of the bitmap to use getPixel
bitmapWheel.bitmapData.getPixel(bitmapWheel.mouseX,bitmapWheel.mouseY);
Upvotes: 1