<p>I have an image (mx) and i want to get the uint of the pixel that was clicked.</p>

<p>Any ideas?</p>

[{'answer_id': 79221, 'author': 'enobrev', 'author_id': 14651, 'author_profile': 'https://Stackoverflow.com/users/14651', 'pm_score': 3, 'selected': False, 'text': '<p>A few minutes on the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html" rel="nofollow noreferrer">BitmapData LiveDoc Page</a> will take you where you need to go.  Once you have your image loaded into a Bitmap variable, you can access its BitmapData property.  Add a <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/MouseEvent.html#CLICK" rel="nofollow noreferrer">Mouse Click Event</a> Listener to the image and then use <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html" rel="nofollow noreferrer">BitmapData::getPixel</a>.  The example for getPixel shows how to convert the uint response to an rgb hex code.</p>\n\n<p>Here\'s a modification of the Example given on the BitmapData page that worked for me (using mxmlc - YMMV):</p>\n\n<pre><code>package {\n    import flash.display.Bitmap;\n    import flash.display.BitmapData;\n    import flash.display.Loader;\n    import flash.display.Sprite;\n    import flash.events.Event;\n    import flash.events.MouseEvent;\n    import flash.net.URLRequest;\n\n    public class BitmapDataExample extends Sprite {\n        private var url:String = "santa-drunk1.jpg";\n        private var size:uint = 200;\n        private var image:Bitmap;\n\n        public function BitmapDataExample() {\n            configureAssets();\n        }\n\n        private function configureAssets():void {\n            var loader:Loader = new Loader();\n            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);\n\n            var request:URLRequest = new URLRequest(url);\n            loader.load(request);\n            addChild(loader);\n        }\n\n        private function completeHandler(event:Event):void {\n            var loader:Loader = Loader(event.target.loader);\n            this.image = Bitmap(loader.content);\n\n            this.addEventListener(MouseEvent.CLICK, this.clickListener);\n        }\n\n        private function clickListener(event:MouseEvent):void {\n            var pixelValue:uint = this.image.bitmapData.getPixel(event.localX, event.localY)\n            trace(pixelValue.toString(16));\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 85391, 'author': 'defmeta', 'author_id': 10875, 'author_profile': 'https://Stackoverflow.com/users/10875', 'pm_score': 4, 'selected': True, 'text': '<p>Here\'s an even simpler implementation. All you do is take a snapshot of the stage using the <strong>draw()</strong> method of bitmapData, then use <strong>getPixel()</strong> on the pixel under the mouse. The advantage of this is that you can sample anything that\'s been drawn to the stage, not just a given bitmap.</p>\n\n<pre><code>import flash.display.Bitmap;\nimport flash.display.BitmapData;\nimport flash.events.*;\n\nstage.addEventListener(MouseEvent.CLICK, getColorSample);\n\nfunction getColorSample(e:MouseEvent):void {\n    var bd:BitmapData = new BitmapData(stage.width, stage.height);\n    bd.draw(stage);\n    var b:Bitmap = new Bitmap(bd);\n    trace(b.bitmapData.getPixel(stage.mouseX,stage.mouseX));\n}\n</code></pre>\n\n<p>Hope this is helpful!</p>\n\n<hr>\n\n<p><strong>Edit</strong>:</p>\n\n<p>This edited version uses a single <code>BitmapData</code>, and removes the unnecessary step of creating a <code>Bitmap</code>. If you\'re sampling the color on <code>MOUSE_MOVE</code> then this is essential to avoid memory issues. </p>\n\n<p>Note: if you\'re using a custom cursor sprite you\'ll have to use an  object other than \'state\' or else you\'ll be sampling the color of the custom sprite instead of what\'s under it.</p>\n\n<pre><code>import flash.display.Bitmap;\nimport flash.display.BitmapData;\nimport flash.events.*;\n\nprivate var _stageBitmap:BitmapData;\n\nstage.addEventListener(MouseEvent.CLICK, getColorSample);\n\nfunction getColorSample(e:MouseEvent):void \n{\n    if (_stageBitmap == null) {\n        _stageBitmap = new BitmapData(stage.width, stage.height);\n    }\n    _stageBitmap.draw(stage);\n\n    var rgb:uint = _stageBitmap.getPixel(stage.mouseX,stage.mouseY);\n\n    var red:int =  (rgb &gt;&gt; 16 &amp; 0xff);\n    var green:int =  (rgb &gt;&gt; 8 &amp; 0xff);\n    var blue:int =  (rgb &amp; 0xff);\n\n    trace(red + "," + green + "," + blue);\n}\n</code></pre>\n'}, {'answer_id': 8619705, 'author': 'darscan', 'author_id': 53303, 'author_profile': 'https://Stackoverflow.com/users/53303', 'pm_score': 3, 'selected': False, 'text': "<p>This is not specific to Flex or mx:Image, and allows you to grab a pixel color value from any bitmap drawable object (provided you have permission):</p>\n\n<pre><code>private const bitmapData:BitmapData = new BitmapData(1, 1);\nprivate const matrix:Matrix = new Matrix();\nprivate const clipRect:Rectangle = new Rectangle(0, 0, 1, 1);\n\npublic function getColor(drawable:IBitmapDrawable, x:Number, y:Number):uint\n{\n    matrix.setTo(1, 0, 0, 1, -x, -y)\n    bitmapData.draw(drawable, matrix, null, null, clipRect);\n    return bitmapData.getPixel(0, 0);\n}\n</code></pre>\n\n<p>You could easily grab a pixel from the stage or your mx:Image instance. It's a lot more efficient than drawing the entire stage (or drawable object), and should be fast enough to hook up to MouseEvent.MOUSE_MOVE for instant visual feedback.</p>\n"}]
['https://Stackoverflow.com/questions/78849', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1748529/']