How to embed a JSON file in AS3 with Flex

JSONFlex now has native JSON support but there’s not much written on the interwebs about how to use it yet.  After fiddling around a bit I brewed up this super-handy, super-tiny class to help convert an embedded JSON file into a usable object.  I’m sure I’ll be getting plenty of use out of this snippit in the future and I hope it proves useful to you as well…

 

Magic EmbeddedJSON Class…

 

 

Sample File (this is what we’re embedding)…

 

Let’s use it to load this ridiculously simply JSON file.

On disk, my test file’s name is “filename.json” (Oh my! What a suitable name!)

 

How to Embed it…

 

Its use couldn’t be more simple, which is part of what makes it so darn handy!  Simply import the EmbeddedJSON package and then embed the JSON file.  We’ll also need an Object variable to hold our data after it loads.

 

How to load it… 

 

To actually load the data, simply pass the Embedded class into EmbeddedJSON.load() and it’ll pop out a newly parsed object, ready for you to parse into your game engine.  Neat, huh!?

 

Your Turn…

 

If you found this helpful, please help to spread the word by clicking any of the quick share-buttons below.  This will also encourage me to write similar blog posts in the future.

 

And as always, if you have any questions or helpful tips/resources, please feel free to leave a comment below.  It only takes a moment and self promotion is encouraged if topics are related.

 
Thank you for your support!
 
-John Hutchinson (Level X Games)
4 thoughts on “How to embed a JSON file in AS3 with Flex

Leave a Reply

You are allowed to enter 1 URL(s) in the comment area.

20 − fifteen =