Query Graphics Data – Live demo

I wanted to post the demo of the example I posted the other day as a video. It is using the new Query Graphics API we are introducing in Flash Player 11.6/AIR 3.6. Make sure you have Flash Player 11.6 and check the demo below. Just click anywhere to sample the graphical objects from the MovieClip then reconstruct it at runtime:

Get Adobe Flash player

Here is the very simple code below, note that the API is now called readGraphicsData. You can download the full source code here:

	import flash.display.IGraphicsData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	[SWF(width="900", height="400", frameRate="30", backgroundColor="#FFFFFF")]
	public class TestGrabby extends Sprite
		private var b:BigBilbo = new BigBilbo();
		private var v:Vector.<IGraphicsData>;
		private var result:Vector.<IGraphicsData>;
		private var copy:Sprite = new Sprite();
		private var inc:int;
		private var count:int;
		public function TestGrabby()
			b.scaleX = b.scaleY = .7;
			copy.scaleX = copy.scaleY = .7;
			b.x = 240;
			b.y = 200;
			addChild( b );
			copy.x = 650;
			copy.y = 200;
			addChild ( copy );
			stage.addEventListener(MouseEvent.CLICK, onClick);
		private function onClick(e:MouseEvent):void
			// reset
			inc = 0;
			stage.removeEventListener(Event.ENTER_FRAME, onFrame);	
			// sample
			v = b.graphics.readGraphicsData(true);
			count = v.length;
			result = new Vector.<IGraphicsData>(count, true);
			stage.addEventListener(Event.ENTER_FRAME, onFrame);	
		private function onFrame (e:Event):void
			if ( inc < count )
				result[inc++] = v.shift();
			} else stage.removeEventListener(Event.ENTER_FRAME, onFrame);

I hope you guys will like it!

Comments (19)

  1. javid wrote:

    good ! tnx

    Sunday, December 9, 2012 at 12:01 pm #
  2. Gary Paluk wrote:

    Great new feature in my opinion. Thanks

    Sunday, December 9, 2012 at 1:27 pm #
  3. javid wrote:

    I try it but give me an error :

    Exception fault: ReferenceError: Error #1069: Property readGraphicsData not found on flash.display.Graphics and there is no default value.

    What should i do?

    Sunday, December 9, 2012 at 1:39 pm #
  4. Thibault Imbert wrote:

    Hi Javid,

    Are you sure you are running Flash Player 11.6?


    Sunday, December 9, 2012 at 3:10 pm #
  5. ozgur wrote:

    what is the use case of this feature? I see that you can generate sprite sheets at run time with it, but what else, please?

    Sunday, December 9, 2012 at 11:12 pm #
  6. Thibault Imbert wrote:

    Hi ozgur,

    Many different things, sprite sheet is one, another very useful is for serialization/deserialization of display objects. With this feature , you can describe entirely a display object and save it as an XML file for instance and save that to reuse later. AMF does not support display object, this feature allows you to circumvent this limitation.

    Also, lets say you wanted to export any display object to SVG or any other format, you can do this with this feature given that the display object is entirely described.


    Monday, December 10, 2012 at 5:33 am #
  7. Senthil Kumaran wrote:

    Also we can burst any movieclip… :)

    Monday, December 10, 2012 at 7:15 am #
  8. Interesting stuff, keep it up!

    Monday, December 10, 2012 at 11:57 am #
  9. This really looks superb. Great to see support for gradients has made it in. Any other changes to the list of supported graphics features?

    Monday, December 10, 2012 at 10:43 pm #
  10. Senthil Kumaran wrote:

    Can we apply transformation to Graphics data before drawing?

    Tuesday, December 11, 2012 at 7:58 am #
  11. Elliot Geno wrote:

    Does Bitmap fills work as well? Also how fast is it? Just glancing at the code, it appears you slow it down to show what it can do. But is it almost instantaneous or is it a pretty expensive task?

    Tuesday, December 11, 2012 at 8:20 pm #
  12. Eiven wrote:

    I find it interesting for
    triangulation of 2D Polygons.

    Wednesday, December 12, 2012 at 4:25 pm #
  13. Rackdoll wrote:

    HI Thibault,
    Do you have some performance numbers for us on this subject ?

    THnx in advance!

    Friday, December 14, 2012 at 2:13 pm #
  14. Reacol wrote:

    Your entire work to advance Flash Player forward is really awesome ;) Thank YOU!!! Happy NEW YEAR!!!

    Monday, December 31, 2012 at 5:22 pm #
  15. ben w wrote:

    Hi Thibault, had a quick bash at some rendering of the graphics data on the GPU:
    Still a long way to go but initial results are promising.

    Thursday, January 10, 2013 at 5:51 pm #
  16. Thibault Imbert wrote:

    Hi Ben,

    Really cool example of use of the feature. Keep me posted ;)


    Friday, January 11, 2013 at 2:56 am #
  17. Patrick wrote:

    does anyone know why Create Projector has been disabled since FP 11.2?
    we use that all the time to create exe’s to play flash locally for users that can’t play swfs…this was an important option for us to have.

    Friday, January 18, 2013 at 9:50 pm #
  18. This is great, although the resulting ByteArray is quite large, are you guys working on a better compression?

    Tuesday, February 12, 2013 at 3:51 am #
  19. civet wrote:

    I modified line48~49 to:
    result.length = 0;
    result[0] = v[inc++];
    and do not set result to fixed-length
    also work!

    Sunday, February 17, 2013 at 5:31 am #

Trackbacks/Pingbacks (2)

  1. Vector graphics on the GPU with Stage3D « flashing in public on Thursday, January 10, 2013 at 3:07 pm

    [...] Cool so now that I was able to render filled triangles and bezier curves (and soooooo close to cubic curves too – need help on this one though), I thought it should be easy to tie it in to the new readGraphicsData command as seen here: Query Graphics Data [...]

  2. [...] Update: This feature has shipped in Flash Player 11.6/AIR 3.6 – See here. [...]