Reputation: 12337
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.
Upvotes: 3
Views: 3247
Reputation: 12420
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));
}
}
Upvotes: 1
Reputation:
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.
Upvotes: 4