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!