AS3 PNG Encoder without BitmapData - actionscript-3

Simply stated, I'm looking for a PNG encoder that will directly convert a RGB/RGBA ByteArray into a PNG file also stored in a ByteArray without making use of the BitmapData class at all. I'm currently working on a ~v4.0 Scaleform Gfx project - which doesn't support any of the Get/SetPixel methods.

If you're using Scaleform 4.0, then likely your best solution is to bind the ByteArray in question to a GFx::Value in C++, via an ExternalInterface call. With the GFx::Value, you can use ReadByteArray, WriteByteArray, etc.
Scaleform 4.0 by default has a PNG reader/writer built in, Scaleform::Render::PNG::FileReader/FileWriter. These basically just wrap libpng functionality. You can use Scaleform::MemoryFile to wrap the incoming/outgoing bytes, so they can use this interface.
Alternatively, if you'd like to use the BitmapData API, you could upgrade to the final version of Scaleform, which is available from Autodesk support for free, assuming you have a valid license.

Related

How to make the spritesheet exporter for easeljs/createjs in flashCC works with easel 7.0?

Flash CC html5 exporter uses easeljs 7.0.
In this version the BitmapAnimation is deprecated and replaced by Sprite.
However, the spritesheet exporter for easeljs of flash cc still uses BitmapAnimation, making it incompatible.
Am I missing something ?
Does anyone have run into this and solve the problem ?
EaselJS up to v0.7.1 still supports BitmapAnimation via an alias back to Sprite. The current version of FlashCC uses Sprite, however it is not compatible with EaselJS v0.8.0 due to dependency on the old inheritance model. The vNEXT of EaselJS is compatible with it, and we are working with Adobe to update FlashCC's export format to be more flexible and forward compatible.
The spritesheet data exported is still completely compatible, just not the Sprite it generates. In the worst case, you can just copy the data out, and write the code to instantiate the Sprite yourself.

AS3 to Generate Dynamic SWF?

Is it possible, using AS3, to programmatically generate a .swf file? What my little app does is load a bunch of images, using FileReference, now I want to compile them into a stand-alone swf that the user can download (the swf will be a slideshow).
[edit]
There seems to be some mis-understanding of what I am asking. I want to have one compiled swf from which the user may select some images and press a button whereby the swf will create and compile a second swf containing said images. As this is a stand-alone app, there will be no server-side interaction.
What I am thinking is that there will be a string representing a dynamic class. When the user selects their images the appropriate embed tags are added to this string, which is then compiled and saved to the user's desktop.
So my question is, can a compiled swf generate and compile a second swf?
Take a look at this library, this allows you to create a .swf at runtime.
https://github.com/claus/as3swf
It should be possible to do server side, by generating the relevant code and running the as3 compiler.
I haven't investigated the package thoroughly, but the As3Eval library seems to be doing what you're asking - realtime compilation of AS3 into executable bytecode (on the client with no server interaction). Check out the demo.
I'm not sure it would support image embedding - perhaps you could encode the image data as a base64 string in your dynamically built source code.
You could also use swfmill, a command-line tool to create SWF files from XML documents.
It's not well documented but for basic usages (such as creating asset libraries) you should find what you need.

How to use library of other languages in Action Script 3?

Is there any way to use the library of other language in Action Script 3 ?
For C/C++
I learned that we can use Alchemy: http://labs.adobe.com/technologies/alchemy/
But for other languages (here I mean Ruby or Java), can I use their libs via AS3 ?
Alchemy is a cross-compiler from LLVM to ABC, if the language you are interested in can compile to LLVM, then, in theory, you can compile to ABC. So, Alchemy supports (with some tweaks) also C# or Java (but you will have to spend some time getting them to work together, there's no out of the box solution).
AIR (which is a desktop variant of Flash) can use something called "NativeProcess" which means that granted the operating system can execute the code in the library, then you can do so by creating a new process that calls the function from the library you need.
In AIR, again, there's a new feature called ANE (AIR Native Extensions) - this allows you to bind AIR more tightly to the native code. But, it doesn't need to be native as in object files only, it should be something the underlying system can execute. But I have to confess, I never tried creating any such extension, so my knowledge of it is theoretical.
No you can not use Ruby or Java code/libraries in Flash. Alchemy only allows you to use C and C++ libraries. The only way is to port those libraries to ActionScript, or maybe the library you want to use has already been ported to AS3.
It is also possible that there is something similar in AS3. You could ask another question here or on an Flash forum if anyone knows if the library you need has an equivalent in flash.

Encode video from any format to .flv format in AS3

Is there any library in Action Script that be able to convert any video format to .FLV?
I've been looking for it with no success. I thought that as3 had functions for that purposes but not found.
I want to give the possibility that in my site, users can upload any video, so I need to convert it to a standard and compress it to a fixed resolution.
Thanks in advance.
There's a FLV encoder AS3 library. As far as I remember it requires image bytes and audio bytes for a frame. But you will have to get image data and sound data somewhere. You could either
play the video in flash and grab 'screenshots'
decode it and get actual data
In the first case you'll end with a mp4/flv -> flv converter which I guess is not what you need. In the second case you will have to decode videos somehow. So you either will have to implement decoding algorythms in AS3 or use Alchemy and existing C/C++ solutions.
Adobe is messing up with Alchemy at the moment, so I guess it is not an option anyway.
But everyone in their mind uses a server-side script to convert videos. There are tons of articles in the web. This will be the simplest, fastest and least painful solution.

Execute dynamic algorithms in AS3

I have a Flash in AS3. I want to dynamically load code that performs some kind of calculations. Is it doable with AS3 (I've read that there is no eval)? Should I use an interpreter in AS3 that gets the data and does the calculations?
My first thought was to load an external swf that does all the calculations but I think having an engine that gets input from a socket is more elegant as a solution.
So, how is it possible to execute algorithms that come from a server in a swf file?
Well, there is an AS3 Eval Library by metalbot. You should probably take a look.
Also you may use browser JS engine to perform JavaScript eval with code downloaded from server. Look at ExternalInterface AS3 class for that.
If number of your code snippets is limited you could use special swfs (prepared beforehand) with those code snippets, downloaded from server. After loading an swf you can use it's codebase without any evals.