Extract all png file and bitmap data from swf using as3 - actionscript-3

Is there any way to get a list of bitmap resource (eg png file) using as3? I know that I can go through the all child of the swf and check if each child is a shape or not, if yes, then I can get back the bitmap data by
var bmd:BitmapData = new BitmapData(obj.width, obj.height, true, 0);
bmd.draw(obj);
and then write out the bmd as a png file. However, by doing this I cannot know which png resource this object associate with, also if the object instance is inside an animation, this approach may not successfully capture the bitmap data correctly. Any better idea?

I believe you can play with these libraries as3swf (as3swf is a low level Actionscript 3 library to parse, create, modify and publish SWF files.) and Velocity 9 SWF Inspector (A handy little tool to peek inside SWF files)

Related

Is it necessary to import actionscript files through timeline actions?

It seems as though every actionscript file (not custom ones) is automatically included when coding in the timeline's actions, so I'm wondering if it's necessary to import the files through the code. Are there any advantages? Can I prevent flash from importing every file to reduce the size of my flash application (SWF)?.
For example, I don't need to import MovieClip to use the MovieClip class in timeline actions.
You can indeed load external assets, that is, anything of SWF, MP3, WAV, JPG or any byte sequence you have a decoder for, then parse it via code, then use in your Flash app. The advantages are flexibility, for example, if a user has all sounds turned off, you are free to not load large music for him thus saving him some traffic - this might be crucial for some people out there. There are also disadvantages, because the files (assets) in SWF are available from the start of your app, and because the connection can get lost at any moment, you might not receive your external files in time for the app to use, or not receive them at all.
Not importing in order to reduce the SWF size? I'd say reduce the size or quality of those assets instead. The actual mess with Loaders is something you should avoid unless you have dynamic downloadable content (some extra levels' metadata maybe) which you plan to generate on a timely basis in order to attract longer attention to your app.
In short, all static content is better embedded, all dynamic content should be loaded afterwards.
Compiling FLA file doesn't embed every AS file in the resulting SWF. My test directory structure.
Work Directory
file.fla
ClassA.as
ClassB.as
The code on my timeline.
var a:ClassA = new ClassA();
The resulting SWF only contain the ClassA.
For multiple SWF files with code, every SWF embed the class. It's your job to tell the compiler.
If you are using FLEXSDK, you can look to these parameters.
-link-report file.xml : Generate a file containing all AS file include at compilation.
-load-externs file.xml : Exclude all class containt in the file.
If you are using Adobe Flash exclude class article

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();

AS3 load bitmapData from JPG/PNG bytearray synchronously

Given a ByteArray containing JPG or PNG data, is there a way to retrieve synchronically a corresponding BitmapData in Adobe AIR?
JPEGDecoder
PNGDecoder
Otherwise, use loadBytes. I'd say use loadBytes, since it won't halt your thread.

Is there any method in as3 that flash can write file's last modified date

Is there any method in as3 that flash can write file's last modified date.
Its stand alone flash application which had external swf loading. I want to check the last modified date of the swf during the loading.
please suggest any possible methods.
Thanks.
In AIR, there is File class with modificationDate property. But in plain AS3, there's no file concept at all. If you loading swf with Loader, you only get data, but not the attributes of file (and file might not exist at all if loading something by URL.)

Converting SWF into GIF file

I have a flash file where I load a remote SWF file into my own. Now what I want to do is convert that remote SWF file into a GIF that I can save onto my server.
The remote file is a SWF that has a variable amount of frames, and I somehow need to be able to figure out the amount of frames (I presume), and take a snapshot (picture) of every frame, to turn the taken pictures into a GIF file. That's what I THINK has to be done, however I have no idea if it's even possible to take pictures/snapshots of remote SWF files.
I need some serious suggestions on how I could get this working. I'm a serious Flash newbie, and anything would help.
Trying to capture stage area using BitmapData
var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
bmd.draw(stage);
And this should help you creating the animated GIF:
http://www.bytearray.org/?p=93
You can use the totalFrames property to see how many frames there are and loop through them. You can draw the frames into a BitmapData object.