ActionScript3 - Saving objects created when application is running - actionscript-3

I made an editor that allows to create some custom space ships for game I'm making.
This editor is meant for the player and his ships are saved in SharedObject without a problem.
What i would like to do is to use the editor to create some ships for enemies and use them later when designing levels.
I was thinking about writing the Ship object to ByteArray and than tracing them so i can copy and paste them to code and read them back to object but this does not seem to work since what i get from tracing a ByteArray is only class name and few undefined symbols that i can't even paste here.

The standard trace panel in flash is text based, therefore no bytes can be output properly (ByteArray).
I'm not pretty sure what are the types of objects you need to store, but you can do two things:
Save ByteArray to UTF8 external file; then read it back to ByteArray, and you're on the road again
if you need to trace them out, Base64 encode them (simple but powerful class here: https://gist.github.com/burakkirkil/4051420)

Related

AS3 Air — Check a Zip to get Audio File

I have a problematic situation that I wish to expose you because it contains some opposites constraints. Maybe someone will have an idea on how to unlock my problem.
I'm going to make a mobile application with ActionScript 3 and Air for iOS and Android. This application has to download zip file which it uses to display text, bitmap and sound.
This last one is the problem.
After some research, one of the best way I found to check a zip file is FZip, but it allows us to get data from zip on a ByteArray form. And a Sound can't be converted from ByteArray. ( That's what a lots of results about it appear to say. )
One of the solution proposed is to put the ByteArray of a sound and put it in a SWF. Then take the SWF from the zip to get the Sound.
I can't do that because this zip will be uploaded from a admin interface used by anybody. I can't force them to use Flash.
I have few potential direction where I ask for your advices :
• Use Code or Native Extension ( iOS and Android ) to check a zip without files read in ByteArray
• Convert a ByteArray into Sound without have to pass it in a SWF
• Dynamicly create a SWF with the ByteArray of a Sound
• In the last possibility, another way to drag and download few files together which can be consulted in another format than ByteArray ( Like a iOS Bundle but with android too )
Thanks a lot to help me,
You can simply write the ByteArray on a local mp3 (or mp4) file and then play it, to write a ByteArray to file see documentation here.

Some way to change text of SWF without having Flash?

I have a FLA with some text but the person that will be sending the SWF doesn't have Flash and doesn't know anything about Flash either.
Is there some way to build the FLA so that the text can be changed simply by modifying the SWF somehow? Due to company policy, the SWF cannot read from external files.
We tried programming into the FLA that it read an XML in another server, but that's not allowed. I also cannot send the SWF with another file (ie. an xml file).
Thanks.
Use FLASM or SWFMILL which are free command line assembler/disassembler for swf files. Use any of the one to disassemble your swf. You can open the result file in any of the text editor, find and replace your text and assemble it as swf again. Hope it helps.
It is a strange logic to try to modify a FLA file without Flash. A FLA file is a binary file, you'll need an editor to read it and I'm pretty sure Adobe isn't allowing 3rd party editors legally.
But yes, it's fine to have a dynamic TextField where you can send the parameter and change the data. Please note - you need to send the data. Means it has to come from outside.
What are the options? Well, actually, there are few:
Loading from an external file or getting it from a server side script. You said it's not allowed, let's omit this method.
Read FlashVars. If you publish it within a HTML page, you can actually feed some data via FlashVars. Not only 1 variable, but as many as you want. And it's fine for small strings, but if you plan to pass a text larger than a sentence… Don't do it.
As a funny hack you could try naming your file with the text you want and read the URL of the SWF thus showing it's name and using it as a text data. But don't do it :)^
If you want to try it, you can access the URL with stage.loaderInfo.url, just make sure you have a stage defined - call in the document class or after the display object you're calling from is added to stage.
Use ExternalInterface to communicate with, for example, JavaScript and get the variables from JavaScript. It's actually not so bad, since your text will be tidily stored in a .js file and you can modify it on the run. That of course is a separate file and you need to have the SWF embedded in HTML for that, but it is one of the options you have.
Other than that you could have an external file that will hold the data and embed it in the SWF. Look more on embedding here: http://flashgamedojo.com/wiki/index.php?title=Embedding_XML_in_AS3 . It is about embedding XML data, but you can use the technique for any data, even binary.
Embedding data is a great thing, but you'll need to re-compile each time you make a change in the file, since it isn't loading the file dynamically, but embeds it into to the SWF itself on compile time.
Hope that helps!
JPEXS Decompiler can change text in an SWF pretty easily. It's still actively developed as of 2021.

Exporting AS3 animation to FLV using AS3

Is it possible to export an animation consisting of AS3 etc etc into a FLV file type using AS3 Code to do it rather than using manual progression
File > Export etc etc
Thanks
Aiden
It is a long shot, but depending on the conditions (CPU power, resolution, memory) it could work.
You should be able to make a BitmapData for every frame in your movie using bitmapData.draw(displayObject);. Then store all those bitmaps in an array, and then encode to flv using some external library such as this one.
Here's a tutorial on how to convert a displayObject into a BitmapData.
If instead of using Flash Player you compile to Adobe Air for desktop, you could save the frames as files in the hard drive, and then encode the sequence using a multitude of programs (such as After Effects) to any video format you want.
You can look into this codebase, it may save you some time:
http://www.zeropointnine.com/blog/simpleflvwriteras-as3-class-to-create-flvs/
var myWriter:SimpleFlvWriter = SimpleFlvWriter.getInstance();
myWriter.createFile(myFile, 320,240, 30, 120);
myWriter.saveFrame( myBitmapData1 );
myWriter.saveFrame( myBitmapData2 );
myWriter.saveFrame( myBitmapData3 ); // ... etc.
myWriter.closeFile();

three.js update geometry of json file

i am working on a project and i got stuck on this one thing, i got a bvh file with an animation which i put on a biped in 3dsmax then i export every frame in to a json file with the thee.js json exporter and then when it gets played i remove the old mesh and add a new one. This causes the model to upload multiple times, which ofcourse is not what i want.
I use the jsonloader and i wondered if there was a way to update only the geometry every frame? Also i made those seperate files because i dont use a skin and i dont have morphtargets because i use a bvh file in 3dsmax.
It would be awesome if someone could help me with this
Example: http://www.deschaatssport.nl/3dsportsvisualiser/versie3/?p=3# (press the play button)
Mathijs Jansen
Assuming your JSON exporter keeps the number and order of faces/vertices intact, you could do something like this:
Load the initial model as you do now
Set geometry.dynamic = true;
Load the rest of the JSON files with plain old AJAX (alternatively you could combine the frame JSON files to one file, whatever so you have access to all of them through your own code)
For each frame, loop the new frame vertex position array (found in the JSON for each frame) and overwrite the coordinates of your existing geometry vertices (geometry.vertices[i].x = myframevertices[i][0]; etc...)
Set geometry.verticesNeedUpdate = true; and render the frame.
Again I'm just assuming that each JSON file has the same amount and order of faces/vertices, and only the vertex positions change in each frame. I'm not completely sure if it works like that.
There has also been some (experimental?) work on BVH support with Three.js. You might have success searching around, I don't know if there is anything usable though. One related effort here: https://github.com/akjava/BVH-Motion-Creator

How to join multiple mp3s into one downloadable mp3 file in Flash AS3?

I have a couple of short mp3 files that the user can reorganize on a timeline. After that, I want to save the result as one mp3 file, combining six short ones.
In other projects I have done microphone recording, compressing to mp3 using the alchemy ShineMP3Encoder, and saving that as a file.
I see at least two approaches:
Extracting all ByteArray data from the loaded Sound objects,
concatenating that in a new ByteArray and compressing that with
Shine. However the ByteArray from Sound.extract doesn't seem to be
compatible with the encoder, telling me "Error : Input not a
MS-RIFF file"
Somehow combining the raw MP3 files without the need of decoding
and encoding. But that would mean having to strip off file header info
and such.
If impossible or very inefficient in Flash, I would consider a server side solution in PHP. So if that would be easy, please let me know.
Thanks!
Do these need to be physically combined into a single file; ie does the Flash need to actually generate a single MP3? Or just played back to the user as if they were one long file?
Flash does not have any built-in capacity to encode MP3s, though various I believe Flash Media Servers have that capacity (Red5, etc.). Actually, on exploration, here is a link to a guy who claims he has technology that will allow you to record an MP3 client-side, though it appears to be more for audio recordings from a built-in mic:
http://fms.denniehoopingarner.com/
Perhaps you could work with him to alter the code to work with existing sound files and generate a new one. Otherwise, you will probably need to do it with some fancy server-side footwork.
It turns out it is in fact easy to combine multiple mp3 files. You can just concatenate their raw data and save it out as a new mp3 file. A few conditions apply:
Make sure all compression settings are identical and non-dynamic. Bitrate, frequency, stereo/mono, etc.
The end result's length indicated by your OS or an mp3 player might be wrong, and show the length of the first segment only. This is header-data. Most players, including Flash, will just play the whole file though, so in most situations this might not be a problem.
In this example I'm using Greensock's LoaderMax library. DataLoader is the specific loader type you want to use (should be binary by default). *Note that I'm using the url as the name to identify the loader later, and some *_variables* need to be declared as class members*
Of course you could use the native way or a different library to load your files too.
for each ( var mp3FileURL : String in _mp3FileURLs )
{
var loader : DataLoader = new DataLoader( mp3FileURL, mp3FileURL ) );
_preloadQueue.append( loader );
}
When loading the queue is complete, you can start processing the data from the loaders.
_audioEditMP3 = new ByteArray();
for each ( var mp3FileURL : String in _mp3FileURLs )
{
var content : * = _preloadQueue.getContent( mp3FileURL );
_audioEditMP3.writeBytes( content );
}
You are now ready to save the file!
var file : FileReference = new FileReference();
file.save( _audioEditMP3, "myAudioCompilation.mp3" );