Reputation: 6655
I have potentially an interesting situation. I'm developing a dynamic drawing tool using shapes and I need to be able to store the current "state" of the objects in a database.
The "shapes" will be simple geometric along with custom-drawn shapes so i can't just store the geometric footprints of them.
Here's an example screen shot (simple shapes):
During use, these shapes can be dragged, resized, rotated, deleted and split into smaller shapes so their current properties need to be retained.
Any ideas? I just need a starting point.
Upvotes: 1
Views: 461
Reputation: 17217
you could write/read your data as ByteArray objects to the file system. this is particularly useful if you're developing an AIR application since you have the option to encrypt your data using the EncryptedLocalStore class (currently for desktop deployment targets only).
Upvotes: 1
Reputation: 2941
I suspect there are going to be some application specific circumstances, but this is how I would approach it (I have done similar things before):
flash.utils.describeType
returns so you can dynamically instantiate the objects.Depending on your needs you may need to save off filters, transform, etc.
To reconstruct, you essentially do everything backwards. Just be careful with your stacking order to make sure you layer things the same way.
This is pretty simplified, but should be a start. If I were doing this, I would put some more thought into doing essentially the same thing, but with a better object-oriented approach.
Upvotes: 0
Reputation: 30258
I'd probably recommend exporting and importing from a subset of SVG.
Try http://code.google.com/p/as3svgrendererlib/ this library, you may find it useful.
Upvotes: 0
Reputation: 63748
One typical approach is to store the set of drawing steps, and then re-parse these after loading them. i.e basically store a list of drawing commands. This also lets you unwind your drawing without too much extra work, do collaborative drawing, etc. It's a nice approach and very low-memory for uncomplicated scenes too.
It's not really important, but I think this is how Flash does drawing itself anyway when you draw primitives on a Graphics
object.
Upvotes: 0