0
votes

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.

1
Sorry. I created a .fla file with the .jpg image inserted on the stage, then converted the .jpg file to a bitmap, and created the custom class.UMich_2017
Yes, true. Still getting the same error after trying what you said. If the base class is BitmapData, why would I define bitmapWheel as a Bitmap?UMich_2017
As you have it, with your bitmapWheel var, you are just creating a new empty BitmapData that matches the width and height or your sWheel bitmap data. your sWheel instance is already BitmapData, you don't need to create another bitmap data var.BadFeelingAboutThis
You have some inconsistencies with how your spell bitmapWheel (eg. uppercase M sometimes).BadFeelingAboutThis
Thank you for all of the help! Solved.UMich_2017

1 Answers

1
votes

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);