Google Answers Logo
View Question
 
Q: Flash MX Actionscript: how to determine RGB of a point? ( No Answer,   0 Comments )
Question  
Subject: Flash MX Actionscript: how to determine RGB of a point?
Category: Computers > Programming
Asked by: g8z-ga
List Price: $10.00
Posted: 08 Apr 2003 10:29 PDT
Expires: 24 Apr 2003 09:03 PDT
Question ID: 187732
Hello,

I'm using Macromedia Flash MX to create a simple color picker. You can
download the .fla and .swf files of what I have so far from
http://www.tufat.com/ColorPicker.zip

Here's the problem: I need a way to determine the RGB value of a point
on the stage that the mouse is positioned over, so that I can update
the little text box indicating the chosen color when the user clicks
on a color.

Thanks,
Darren

Request for Question Clarification by skorba-ga on 17 Apr 2003 15:21 PDT
Dear Darren -

I will add this as a Request for Question Clarification, even though I
believe it is a good enough answer. The reason for this is simple:
what you ask for can not be done, not the way you pose the problem.
But fortunately your problem is easily solved, with some algorithm
work.

1) In flash actionscripting you don't work with pixels the way you
would in f.i. a java applet (which I see from your homepage that you
are familiar with). The drawing mechanisms are all based on lines and
fills, and not pixels. (You don't have a PixelGrabber or any other
useful class like you would have in the old java.awt.* package).

2) But we can rephrase the question: Instead of asking what the value
of a point is, we can ask how to best store the color value of a pixel
WHEN WE DRAW THE COLOR PICKER, and then simply use these values as a
reference (since we can always ask for the coordinates of the mouse
pointer).

For your convenience I have put together a set of files that do
exactly this. You can find the files at

http://www.orgdot.com/ColorPicker/

The project named colPick consist of a) the exported movie, and b) the
source project.

The technique is simple: First I make a subset of the colors (in this
case all the websafe colors), since 255x255x255 colors are way to much
to display on a regular flash movie. Second, I store each color value
inside a movie clip that consists of a button. Third, on the rollOver
action of this button, the text fields are updated to tell which color
that specific movie clip consists of.

3) This method again has it limitations. For large subsets of colors
it is cumbersome (and CPU-intensive) to keep a single movie
clip+button for each color. If you want to use a large number of
colors, the best method by far is this:

Use f.i. java (since that is a familiar tool to you) to generate a
large bitmap gradient with the subset of colors that you need. Then
you import this bitmap into your flash application. Place the bitmap
at (0,0) in a movie clip. Now you can have a single loop that just
needs to look up the same value as was returned in when the gradient
was drawn - based on the x/y value of the cursor.

Of course, what you need is a algorithm (function) that will exactly
duplicate the drawing you did when generating the bitmap. I have
included an example of both a java applet that generates a gradient,
and a flash movie that 'reverses' this behavior.

The project named colPick2 consist of a) the exported movie, and b)
the source project, and c) col.java, a source file giving an example
of a generated gradient.

As always, you are advised to modify this code to suit your needs.

Good luck!
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy