AS3 and hashing - actionscript-3

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.

Related

How to create a Flash Movieclip via a web interface?

Forgive me if this is not the correct place to ask such a question.
Basically, I am looking for a way to allow someone to easily (at least, easier then diving into Flash) create a basic Flash animation (movieclip) with some placed image assets and text, all via a web interface.
I was thinking along the lines of using jQuery to allow drag and drop assets, of which you'd "record" the co-ordinates and relay that to Flash somehow to create the SWF file.
Or would it be better to create a tool in Flash (surely making operations easier) and then have some kind of "save" button to render out the SWF?
I'm totally open to suggestions.
Thank you
If you really need to produce a stand-alone SWF file (and not just a config file for you own "player"), I would probably do it like this;
1) Create your editor in whatever system you feel like (flash, jquery etc).
2) Build a config file in the client. This is used, together with all the resources the user added, to play back the animation.
3) Upload said assets and config file to your web server.
4) Use the flex compiler (on the server) to produce the resulting SWF, combining your player with generated AS3 which embeds the uploaded resources as needed, to make it available to the player.
5) Give the user a download link for the newly generated SWF file.
I don't think there is any swf compiler available for Flash (actionescript). You may create a swf that allows users to create an animation, save it as a home-made vector format, and then replay it. But I don't believe you can create and independant swf file with only the created animation in it.
Just think about a player in Flash, and a format that the player will read (xml, json, name it...). You can either generate the input with jQuery or Flash, and then feed it into your player to display it. You will eventually need two files.
Apparently this library allows you to compile SWFs at runtime. I haven't used it myself (yet) and don't know how stable or flexible it is, but it appears to be what you're looking for. I'd recommend giving it a spin and seeing if it's sufficient.
I'm not exactly sure how it saves the file, so you might run into security problems since it's a web application. Hopefully it should be OK though.

Writing text to .txt files using actionscript

Writing text to .txt files using actionscript. how? i couldn't find anything about that in the internet. is that possible? for flash player.
The flash player (the one in browsers) is run through a sandbox which prevents it from accessing or creating files on the users computer (imagine the chaos if it wasn't!), among other things.
You can store persistent data using SharedObject (but this is not readily visible to the user, only useful for storing settings etc).
The other options is to send the data to a web service which in turn would allow the user to download it. Those are your only options really.
Adobe Air is a different runtime, designed to be used for desktop applications. Eg like any program on your computer. It can do a lot more, but has to be downloaded and possibly installed before you can run it (it will not run from within a HTML page).
Check out Adobe AIR: http://www.adobe.com/devnet/air/flash/quickstart/articles/building_text_editor.html
That's impossible from flash player, only from air.

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.

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.