Air - Unzipping file - actionscript-3

Currently I am using nochump library for unzipping files. But its very slow(around 30 seconds for 2 mb file). Is there any other libraries available which are fast. Or is thaere any better way to unzip by communicating with os?
I have used FZip, but it wont work in mac. So cant use it.

Not that I'm aware of... AS3 is quite slow in these areas...
A possible workaround, if you are using zips for loading images, could be using a big JPEG with all of your images inside it (eventually using an aditional XML to determine dimentions, or maybe even custom metadata). Uncompressing images in Flash is quite fast (and asynchronous).

It might be possible using Alchemy (there are very fast Alchemy librairies to encode JPEG and PNG), but I can't find any existing one for unzipping.
Otherwise, you can use the AIR 2.0 beta (not great for production code... depends on your project) to call a native application which will do the job for you.
Anyway, it might get tricky to retrieve progression information if you need it.

Related

Does my AS3 project need a preloader?

I'm just starting to develop an AS3/MXML application on Linux using the command-line Flex 4 compiler. When running mxmlc -source-path=. MyApp/Main.as, I get the following warning:
/home/andreas/projects/as3/MyApp/src/MyApp/Main.as: Warning: This compilation unit did not have a factoryClass specified in Frame metadata to load the configured runtime shared libraries. To compile without runtime shared libraries either set the -static-link-runtime-shared-libraries option to true or remove the -runtime-shared-libraries option.
Another SO answer says that the solution is to link to my preloader. I don't think my project needs a preloader as it's pretty small; can I just ignore the warning?
You should make a preloader, even if your file is pretty small.. the best if you have a preloader, because what's if the user has a very slow internet connection? Or lost the connection while loading.
If your project is really small (like less than a megabyte) and you don't think it will be used widely, a preloader isn't completely necessary. As Zhafur said people with a slow connection such as dial-up might be confused for a while but even so, small apps shouldn't take too long.
However, if you can be bothered, a preloader is probably a good choice for any Flash app embedded in a web page. And if it's small, you don't need anything fancy, just a simple percentage count would do the trick.

What are some good ways to Save/Load files in AS3?

I am writing a game in ActionScript3 using Flixel as a base. I have been unable to find a good method for saving and loading files from the player's local hard drive. I know Flixel has a way to save game data to...I think...cookies that the player doesn't really have access to, and I want to avoid this.
I first learned programming in Java, and one thing I've seen a lot of is scanning (Scanner) and printing (PrintWriter) lines of strings to/from text files. Something like this for AS3 would be my ideal, but if there are other methods I'm open.
Does AS3 have anything in its basic library that can do this task well? Are there libraries I can download and include that do this well/better?
If your game is going to run on a webpage your options are limited. Due to security concerns Flash is limited to reading and writing files specifically selected by the user.
Should you be using Air to make a standalone game, you will have regular access to the filesystem and can write files much like with Java.
If not, you will be pretty much stuck with Flash cookie equivalent, SharedObject.

AS3 and hashing

Is it possible to hash flv videos so it is unplayable by itself and the format is unrecognizable by softwares, but i could actually de-hash them and play in my as3 script?
This is going to be realized on a CD so I can't use server scripts.
no, you can't. not with flv. you could however embed the video into an swf and encrypt the SWF. please note however, using a strong encryption for video data may lead to performance problems.
anyhow: you can load the binary data into a ByteArray, perform the decryption and then load the SWF from the ByteArray.
I'm assuming you mean that you'd like to do this "real time" in the app.
If so, there are two issues with that:
you will have to decrypt your custom video in software, so its going to run very slow. And depending on the end user's computer, unpredictably so.
As ALOToverflow previously mentioned, the key to your hashing algorithm will be in your .swf which can be simply be decompiled to reveal it.
Assuming you are using as3 with adobe AIR you could potentially ship your users "broken" flv's and then simply repair them before you attempt to play them back.
Depending on the resolution and length of the videos this might be a viable alternative.
(you'd utilize the FileStream Class for this.) http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html
FLV's all start with a standard header, so you could start by just breaking the header, and repairing it later. (I'm talking about getting down and dirty with the binary code btw.)
http://en.wikipedia.org/wiki/Flash_Video
I created a similar project once.
this is what I did:
I encrypt the videos somehow, does not mater how, put them into one single big file.
A bulk data file. Then I run the swf, NOT from browser but rather run it from a JAVA application, which can decrypt the bulk video-file waaay faster, than the Adobe swf interpreter.
In the Java app, I pass the decrypted video to the swf as a parameter.
It is good to use Java, because all the clients can open it. Mac users, Windows users, anyone. It is possible to do it with C++, but that would limit your user-base.
Of course anyone with decent knowledge can reverse-engineer the encryption process, but it is harder to get the encryption from a Java compiled software, than from an AS3 swf.
Use Blowfish, Twofish or DES. Do not use RSA, it is slow.
You have to make the Java app extremely fast and simple, so also it is advised, not to use external cryptography libraries.

How can I speed up the compile / publish time of Flash IDE projects

I'm sick of waiting hours for Flash to publish. .NET / VisualStudio projects are WAAAAY faster - is that only compiling the classes that have changed?
Update: Does the Flash IDE re-encode all your sounds and images every time you publish? Can't it cache them somewhere?
In Flash CS4, disabling Warnings Mode speeds up code compilation by about 30% (still quite slow). Strict Mode also, but I'm not sure to what extent.
As for library assets, the optimal speed is achieved by setting JPEGs to "Use imported JPEG data" and PNGs/GIFs as "Loosless PNG/GIF".
As for sounds, I'm not 100% sure, but I think that ADPCM/mono-to-stereo/5kHz/2bit was the fastest.
The [Embed] tag might also help (it doesn't do any convertion) but it includes quite a bit of Flex code.
And as a tip, in Flash CS4 you can batch select assets in the library and apply settings, so you can easily set the optimal speed settings while on development and then change them for deploy.
Uncheck "Warnings Mode" in File > Publish Settings > Actionscript 3.0 Settings. This makes a huge difference. In a recent project I reduced my compile time from 1 min 20 sec down to 7 secs! Yeah, I was astonished too.
For me it turned out that I removed the character filter on my text fields. This seems innocuous, but in fact it has to embed every fracking glyph it can which resulted in a huge swf file that took forever to compile! Anyhow, definitely check that - I think a lot of people could easily overlook this.
You could try to split up your application to separate .swf files and then load them from the main movie.
Also it might be worth to look at your environment. Maybe your machine is running out of RAM, you are using an network drive or your hard disk is encrypted.
Also if the application is getting that big, is Flash really the right technology?
The compiler is just plain slow in the Flash IDE. I can understand the slowness if you have a lot of images in the library that have to be re-exported, but the compiler is inexplicably slow when only compiling code as well.
For example, I have a super basic Away3d scene that requires five full seconds to compile (no library assets). The exact same code compiles in Flex in less than a second. I don't know what's different between the two compilers, but doing any project with a heavy code base in the Flash IDE is just plain painful. As the project grows you'll have to wait longer and longer.
If you're doing a 3D project or something that requires a lot of code compilation, I recommend doing an Actionscript-only project in Flex/Flash Builder. Maybe CS5 will have a better compiler...
You might want to check your character embedding -- If you accidentally click Embed all characters it could embed 1000s of characters, it would significantly slow down your publishing speed
It all depends on your project. I know of some animators that use Flash for publishing broadcast content and that usually takes a long time to publish. There's no getting around it for them. Otherwise, if it takes hours to publish an SWF that will be viewed on the web, then you're probably not going about things the right way.
Additionally, a few obvious culprits that immediately increase the time that it takes to compile a SWF are embedded video and embedded sound. The more items the IDE must compress for output (this includes images too), the longer it will take to compile.
You can't make the Flash IDE cache embedded media (but images won't be reencoded if you import PNGs/GIFs and set the compression to lossless in the library). But if it's a web project you should be loading media from external files anyway, so you don't have to preload all data before anything shows up on the user's screen. You can either load (or even stream) the media files directly or embed them in a separate SWF and load from there, but I don't recommend the latter as it adds unnecessary complexity.
When compiling is too slow, I usually strip down the library - read load images (png, jpg) and sound via URLRequest.
Usually the thing that really slows down the compiler is importing illustrator (ai) files.
disable warnings in the Publish Settings > Flash > as3
If you're even willing to change languages you could use Haxe. It compiles to SWF and is incredibly fast at compiling. It's probably not worth it to change to a different language at the point where you have hour long compile times, but look into it when you are starting your next large project.

wav <> mp3 for flash(as3)

I'm wondering about MP3 decoding/encoding, and I was hoping to pull this off in Flash using AS3
I'm sure it'll be a right pain...
I have no idea where to start, can anyone offer any pointers? reference material?
----much later---
Thank you all very much for your input... It seems I have a long road ahead of me yet!
You could also theoretically do this as a PixelBender filter, and should get significantly better performance than using a pure ActionScript 3 implementation.
More info on PixelBender here:
http://labs.adobe.com/wiki/index.php/Pixel_Bender_Toolkit
mike chambers
mesh#adobe.com
this would help
http://labs.adobe.com/technologies/alchemy/
See LAME MP3 Encoder. You can checkout their source code and their link page. Mpeg.org should have documents too.
I've got a project converting WAV files (actually Asterisk voice mails) into MP3's. If I remember correctly there are some oddities about Lame's license, so I've downloaded and compiled first LAME, then SOX by hand.
I have a web process written in PHP to actually convert the files from WAV to MP3 on the web server's local file system (actually PHP is just supervising the command-line sox tool via exec()). Then I attach all the metadata the MP3 needs using the PEAR Mp3_Id package.
Then I move the newly constructed MP3 file into a folder Apache is sharing, and point the outstanding SoundManager2 flash-based MP3 player at it.
For small transactions this works very well -- converting a minute or two voice mail does not add any appreciable lag to actually rendering and returning the rest of the page. As I get more users on a single server, it will probably eventually become necessary to write a cron job or something to do the conversion before the user actually asks for the file the first time.
It's going to be VERY slow doing this in AS3. You really need a C/C++ implementation if you care at all about how long it will take.
Andre Michelle and the Hobnox guys pulled off something similar with their Hobnox AudioTool, they ported a Java Vorbis encoder to AS3. They supposedly ended up with encoding taking twice the time of the audio duration.
Don't know what your use case is, but in the Hobnox tool apparently audio is created at the client side, encoded as Vorbis, sent to the server, converted to mp3 and stored in the users library.