Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are trying to read the field <code>bmap</code> from <code>e</code> who is a <code>MouseEvent</code> and don't have such field.</p> <p>Also the <code>Bitmap</code> has no field named bData but <code>bitmapData</code>.</p> <p>One way to get the bitmap from the your sprite is to use the target of the event and use <a href="http://www.adobe.com/livedocs/flex/2/langref/flash/display/DisplayObjectContainer.html" rel="nofollow noreferrer">getObjectsUnderPoint</a> to get the bitmap (in case you have multiple bitmap into your sprite)</p> <p>Also don't forget to take the mouse coordinate from the bmap, otherway you will have to play with Point conversion using <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#globalToLocal()" rel="nofollow noreferrer">globalToLocal</a> and <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#localToGlobal()" rel="nofollow noreferrer">LocalToGlobal</a> </p> <pre><code>// function to get the bitmap from a display object container // using the mouse coordinate function findBitmap(container:DisplayObjectContainer):Bitmap { if (container === null) return null; var childs:Array = container.getObjectsUnderPoint( new Point(container.mouseX, container.mouseY) ); while (childs.length &gt; 0) { var ret:Bitmap = childs.pop() as Bitmap; if (ret !== null) return ret; } return null; } // .... canvas = new Sprite; addChild(canvas); canvas.addChild(bmap); //Mouse Track Pixel Colors canvas.addEventListener(MouseEvent.CLICK, readPixel); // ... function readPixel(e:MouseEvent):void { // found the bitmap from the currentTarget var bmap:Bitmap=findBitmap(e.currentTarget as DisplayObjectContainer); var hex:uint=0; if (bmap!==null) { hex = bmap.bitmapData.getPixel32(bmap.mouseX, bmap.mouseY); } var pixelAlpha:int = (hex &gt;&gt;&gt; 0x18) &amp; 0xff; var red:int = (hex &gt;&gt;&gt; 0x10) &amp; 0xff; var green:int = (hex &gt;&gt;&gt; 0x08) &amp; 0xff; var blue:int = hex &amp; 0xff; colorText.text = "Red:" + red + " Green:" + green + " Blue:" + blue + " Alpha:" + pixelAlpha; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload