Hello! Does anyone know how to get the RGB value of movie clip to show in a variable? Example: _root.redBox_mc; var myColors; Anyone? Thanks!
"The RGB value"? Potentially a movieclip contains thousands of colors. If you apply a Color Tint or something to the MovieClip, you can retrieve values via the Color(Flash 6-7) object or the ColorTransform class(Flash 8)
var color = new Color(_root.redBox_mc); var RGB = color.getRGB(); trace(RGB);
That won't work. Or, rather, it will only work to the extent that the clip has already been tinted. In other words, a box authored in Flash as red will not return 16711680(which is 0xff0000), it will return 0, which is basically like saying the object is untinted. If, however, you apply a color tint to the object(no matter what color it was) either in the authoring environment or via Color.setRGB(), it will give you the tint color. You should look up the Color object to understand better what's going on, but also be warned that the Color object is deprecated in Flash 8, replaced by ColorTransform.
I will mention at this point that in Flash 8, you could use BitmapData to create a temporary bitmap from your MC, and use getPixel() to get the color value of a certain pixel(probably it's center), and if your object is solid that will in effect do what you want. Look around, I know there has been made a custom MovieClip.getPixel() method someplace.
I don't want to set any color, I just want to get a rgb value or pixel value to a variable... like this: var color = new Color(_root.redBox_mc); var RGB = color.getRGB(????????); trace(RGB); Like beally says, it will return "0" o my variable... How do I get the value? Is there any sample out there or code? Maybe the get-pixel is the way to go... but how is done? Thanks For The Help Everyone! Best Ney
BitmapData, getPixel, colorTransform are ONLY for Flash player 8. I would use those if you are exporting your movie in Flash Player 8 . You have to let me know more about _root.redBox_mc. Is it just ONE COLOR movieclip? if it is, do you know what its RGB color value is?
Here's my prototype: import flash.display.BitmapData; import flash.geom.Matrix; MovieClip.prototype.getPixel = function(x:Number, y:Number):Number { var bmp:BitmapData = new BitmapData(this._width, this._height, true, 0); var xm:Number = -this.getBounds(this).xMin; var ym:Number = -this.getBounds(this).yMin; bmp.draw(this, new Matrix(1, 0, 0, 1, xm, ym)); var col:Number = bmp.getPixel(x+xm, y+ym); bmp.dispose(); return col; }; Then you can use something like: var col = '0x'+_root.redBox_mc.getPixel(_root.redBox_mc._xmouse,_root.redBox_mc._ymouse).t oString(16); trace(col);
beally, I am only getting
Ney Alencar must have Flash 8 as it didn't generate errors and it returned 0x0 (which happens when you go over a "non-colored" area). var col = '0x'+_root.redBox_mc.getPixel(_root.redBox_mc._xmouse,_root.redBox_mc._ymouse).t oString(16); was just an example. That will get the pixel color under the mouse... if you want to check a specific, (x,y), use: _root.redBox_mc.getPixel(x,y)
Yes, I am using flash8... and I did try your code: import flash.display.BitmapData; import flash.geom.Matrix; MovieClip.prototype.getPixel = function(x:Number, y:Number):Number { var bmp:BitmapData = new BitmapData(this._width, this._height, true, 0); var xm:Number = -this.getBounds(this).xMin; var ym:Number = -this.getBounds(this).yMin; bmp.draw(this, new Matrix(1, 0, 0, 1, xm, ym)); var col:Number = bmp.getPixel(x+xm, y+ym); bmp.dispose(); return col; }; var col = '0x'+_root.redBox_mc.getPixel(_root.redBox_mc._xmouse,_root.redBox_mc._ymouse).t oString(16); trace(col); but what I get is 0x0. Am I doing something wrong? Thanks!
It works with the loop... Thanks You!, Now, if my box has more than one color inside and I want to get a specific color, How do I get the pixel value (color) from y,x location inside the box? Again, Thank for you time... Best, Ney
Don't see what you're looking for? Try a search.
|