I am new to the ActionScript world and I bumped into a problem that is hard for me. I have an SWF file that contains some classes that I cannot recompile from source but want to use again in a different project. I see that SWC files are containing compiled classes that can be easily reused. My question is how could I convert the existing SWF file to an SWC file so that I can use it as a regular library? Google did not help me.
Asked
Active
Viewed 3,132 times
3
-
You could compile your code to an SWC instead of an SWF! – Florent Oct 23 '12 at 08:18
-
@Florent I wrote that I cannot recompile the SWF from source. I even decompiled it and tried to recompile but the decompiler generates uncompilable code. – jabal Oct 23 '12 at 09:37
-
Do you mean you neither have the source code nor the FLA? – Florent Oct 23 '12 at 10:04
-
None of them. It uses a specific version of the Facebook API compiled in that was fixed for the sake of the rest of the program. I have the sources of the rest, but would like to use exactly that fixed Facebook API that is in the SWF. – jabal Oct 23 '12 at 11:22
-
Any update? Maybe you could approve an answer! – Florent Oct 26 '12 at 13:00
2 Answers
3
SWC files use ZIP compression, and actually contain a SWF. If you change the file extension from .swc
to .zip
you can browse the contents and directory structure. It looks like this:
foobar.swc
-> catalog.xml
-> library.swf
With some reverse engineering, you might be able to create a SWC from a SWF by building the catalog.xml
file and packing them together in ZIP file.
But that seems rather complex! You could also simply load the external SWF into your own SWF using Loader. All of the classes, symbols, and timelines of the external SWF will then be available. Of course, this creates a run-time dependency.
1
Since your are not able to recompile your code to an SWC, I suggest you to use a Loader
if you don't need to access the classes as compile-time.
[Event(name="complete", type="flash.events.Event")]
public class SWFLibrary extends EventDispatcher
{
private var loader:Loader;
private var loaded:Boolean;
public function SWFLibrary(urlOrBytes:*)
{
super();
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
if (urlOrBytes is String) {
loader.load(new URLRequest(urlOrBytes));
} else if (urlOrBytes is URLRequest) {
loader.load(urlOrBytes);
} else if (urlOrBytes is ByteArray) {
loader.loadBytes(urlOrBytes);
} else {
throw new ArgumentError("Invalid urlOrBytes argument");
}
}
public function getAssetClass(className:String):Class
{
if (!loaded) {
throw new IllegalOperationError("The SWF library isn't loaded");
}
return loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class;
}
private function completeHandler(event:Event):void
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
loaded = true;
dispatchEvent(new Event(Event.COMPLETE));
}
}

Florent
- 12,310
- 10
- 49
- 58