1

I'm using Actionscript 3 and I need to be able to write a vector graphic sprite to a file and then load it back later. Normally I'd just serialize it in a ByteArray, but apparently you can't serialize a sprite. But it's just data, so there's got to be some way of representing it in a file. I've Googled until my fingers are sore, but I can't seem to turn up anything. Does anyone know how this can be done? Thanks!

Tricky Widget
  • 117
  • 1
  • 2
  • 11
  • Hi, the only way to save it as bytearray is to save as an image and also load into bitmapdata later, but then it will not be a sprite anymore. I suggest you somehow convert it to svg and back, if your sprite is/contains "regular" shapes like circles, rects, lines and so on. – Adrian Pirvulescu Jun 05 '12 at 14:12
  • Yeah, that's why I can't do ByteArray. It's got to be vector, in and out. I'm actually using as3svgrendererlib to load the original art from SVG, but it's too slow for the end-user. Which is why I'm looking for a way to store the sprites it gives me in a more native format. – Tricky Widget Jun 05 '12 at 14:18
  • how about saving your object heierarchy, styles and properties in your own xml format ? ex – Adrian Pirvulescu Jun 05 '12 at 14:30
  • 1
    I've been thinking along those lines. There's the IGraphicsData structure that holds a series of drawing methods, which then then all be drawn at once with drawGraphicsData. If I can dig into the SVG library, I should be able to modify it to output that. Which I could hopefully then serialize. But that's a lot of work... I'll see how it goes. – Tricky Widget Jun 06 '12 at 01:06
  • Indeed, it is a lot of work. You could also create custom shapes, like UIRect, UITriangle, UICircle... and so on. All can be Sprites and have a method that will export they "styles" and "properties" as svg. All you have to do then is to loop them and save the svg. – Adrian Pirvulescu Jun 06 '12 at 07:45

0 Answers0