Using Flash CC to Create Scenarios and use them in any Game Engine

I’ve been using Flash CC to help me speed up my development pipeline. It doesn’t matter if the game is for Adobe Air, HTML5 or any other platform.

For a project I needed to generate this scenario:

Screenshot 2014-05-06 11.23.21

Every part of the scenario was exported as a separate PNG and put it together in a spritesheet using Texture Packer (you can create your spritesheet in Flash CC too)

So, I need the coordinates and Z position of each element in a JSON document I can use in my project. Since doing this by hand would take a good amount of time, and will bring headaches if something have to get changed in the future I choose to use Flash IDE.

The first step is to import all the PNGs in a Flash AS3 document. So you have all of them in a single Layer and stacked on the top left corner.

Screenshot 2014-05-06 11.31.20

Select everything in the scenario, right click on top of the images and choose Distribute to Layers (or cmmd+a and then shft+cmmd+d). Now you have each PNG in a layer with their name on it, this way is easier to localize, isolate or arrange depth.

Screenshot 2014-05-06 11.36.14

You can then import a layer with a flatten reference image to help you arrange the items. I did that, and also tinted the image to visually help me.

Screenshot 2014-05-06 11.39.54

Now you just have to arrange your items on screen.

Screenshot 2014-05-06 11.41.55

Once you have finished, go to the Library and copy/paste the name of the PNG into the Linkage column, this is going to help us identify the class of each item. We’ll remove the “.png” extension with code, so the names match the names assigned by Texture Packer.

Screenshot 2014-05-06 11.51.46

Then we just use this code:

[cc lang=”actionscript”]
import flash.utils.getQualifiedClassName;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.system.System;

var output:Array = [];

for ( var i:int=0; i< this.numChildren; i++)
if ( this.getChildAt(i) is Bitmap)
var b:Bitmap = this.getChildAt(i) as Bitmap;
var bd:BitmapData = b.bitmapData;
var n:String = getQualifiedClassName( bd ).split(‘::’)[0];

var output_string:String = JSON.stringify(output);

cmmd+Enter to run the SWF and we will have the generated JSON on our clipboard. Just paste it in your favorite code editor.

Screenshot 2014-05-06 12.06.46

This code tracks just the name and x/y position and orders the items from bottom to top. But you can easily modify it to track more properties (rotation, alpha, scale, etc.).

And that’s it! Use it in your favourite game engine.