AS3: Saving a sprite to a file and reading it back? - actionscript-3

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!

Related

Exporting multiple animations (tracks) in a single JSON file for THREE.js from 3DS MAX

In the 'Animation / Skinning / Blending' Three.js example, the JSON model (the Marine) has multiple animation tracks (idle, walk and run). These are stored in an "animations" array in the JSON file.
My question is two-fold... Firstly, how do you "label" the animations in 3DS MAX? I tried using an FBX Multi Take plugin which does allow me to add some marking. They are present when I re-import the FBX file back into Max but do not show up when I try to export to JSON... which is my next question....
How do you then export these animation states? When I use the 'ThreeJSAnimationExporter' from within 3DS MAX, there is no option to define any animation tracks (nor will it pick up the ones I defined in the question above), it just exports everything into 1 animation. This is stored in an "animation" (not "animations") array in the resulting JSON file?
The JSON file of the Marine must have been created somehow... can it be done in MAX? If it is only possible in Blender then is there any way I can get my models and animations from 3DS MAX to Blender as I am trained in MAX and don't particularly want to learn Blender, even though it does look very good these days.
Thanks in advance.
P.s. I am using the MAX exporter that ships with r71 of THREE.js.
I have managed to get this working but it requires a lot of inelegant hacking of JSON files and excessive file duplication in MAX. Basically I have created multiple MAX files with the same rig, skin, weights, UV's and materials. I then animated each track of animation and export it using the existing ThreeJSAnimationExporter. I then open up the JSON files, extract the animation entries and combine them into a single JSON file with an "animations" property array instead of a single "animation" property. You can then rename the animation segments from 'Action' to something more useful.
If anyone has a more elegant solution I would love to hear it.
I would also love it if the clever person who created the original ThreeJSAnimationExporter script could create a new script called ThreeJSBlendedAnimationExporter which allows for a simple animation track input system, it would only need a start frame, end frame and animation label for each animation track (segment). And for the love of god, also address the smoothing while you're at it :)

ActionScript3: Cannot save and load objects - AIR

I am trying to create functions to save and load objects. I am storing the objects in File.applicationStorageDirectory...and using File Streams. At some point I thought my code did work, and then it stopped soon after. It also saved the last string I inputed but none of the others. I have pastebinned the functions I think will be necessary, even if someone could point me in the right direction. I am aiming to publish this on an Apple iPad...
http://pastebin.com/61WLLUAB
I am in the process of learning to program, and appreciate any constructive criticism with my layout.
Thanks
I think flash.utils.registerClassAlias() and SharedObjects will be the key for loading/saving objects. Be sure to implement IExternalizable on all objects that will be processed while you save and load your game.
About why does your function not work - first, you don't actually save your state between main sessions, you instead initialize all the objects anew, write them to files and then read them back, thus erasing previous data. You need to try reading an object out of file system prior to instantiating them anew, for each of the charID.IDs you have there. You don't have your IDs instantiated when your Main constructor starts, so Main doesn't know if any of the objects were saved beforehand.

Where should these AS3 variables go?

I am trying to build the foundations for a platformer game in Actionscript 3. I'm still fairly novice at AS3, but I'm hoping this will help build my knowledge.
Anyway,
I understand that I can create Actionscript files that are associated with something such as a Sprite or a MovieClip by extending the Sprite/Movieclip class. I also know about Actionscript files that work as the 'Document class'.
Each level in my game will have different properties that vary such as gravity. Where should I store these variables? Obviously not in the player... Not sure if they're supposed to go in the timeline or the document class, or if they have a separate AS file of their own. I've been told that having global variables is generally bad, so I'm not sure what to do.
You can make levels as separate files that are even not Actionscript, but XML or JSON, since your levels are basically data structures with different starting values. And you can make a Level class that can take such a file, parse it and initialize an in-game level structure based on what's read. Yes, such data should not go to timeline, because should you need to change one piece of that data, it could implicitly affect other game processes. Also, one simple right click can ruin such a game :) I myself use JSON files as my level data holders, and I parse them at the initialization time, you can do like this or say when your level is being loaded.
In short, if something is different by initial data, but common in methods, it should reside separately from main code, or entire code, and be included as data.
I think this similar question and answers will help you somewhat:
As3 OOP game structure (class architecture)
Basically, "What you want to do is to separate what changes in your game from the game itself". So definitely do not include the code in the timeline.

How to scan through a Flash .swf or .flv file and extract a specified number of frames from it?

I would like to be able to
create a folder for the copied video frames
access the individual frames frome a .flv video file and/or .swf file
save these frames to the auto-created folder
I assume one would need to do this using Action Script 3 to scan through the .swf and .flv files and extract the frames.
Are there gudies on how to do this?
You need to know WHAT frames do you want to extract. For example:
extract 20 frames in regular interval from the video clip
extract frames at 15 seconds interval
extract frames at keyframes (scene changes)
I guess that you don't have to use as3 to extract frames, but can also create the script in some other language. Central piece to frame extraction could be ffmpeg, as described in this article.
If it is as3 solution i would do following
- make a loader which loads your fla/flv
- add enter frame event listener to it and on each frame draw loader object to buffer, if you ever done any loading and drawing, this will probably take you 10-20 minutes to set up.
This is pretty much the only straigt-forward solution if you're dealing with code-based animations, videos can be handled in different and easier ways i guess.
You will face the challenge of saving the output tho. Flash player can save images on your computer, however only by prompting you to save the file. You will need to use functions available only in Air player if you want to save anything without prompts.

Creating Bitmaps from ARGB strings (in actionscript-3)?

in actionscript 3, what's the fastest way to dump your data (not from a file) into a bitmap for display?
I have it working with setPixels and colored rects but that's way too slow/inefficient.
Is there a way to load in the raw bytes or hijack the loader class to put in custom loader data?
What would be the best/fastest--should I start writing a byte encoder?
You can quickly copy data from a ByteArray into a Bitmap using setPixels(). Even if you need to do some wrangling of your data beforehand, it should be way faster than setting each pixel individually.