Hail, Stack!
I'm having a little trouble figuring out how to import a SWC file directly in ActionScript, witho开发者_C百科ut setting a library path to the file.
To exemplify, I need something like this:
package
{
[Embed(source = 'Library.swc')] // This line won't work, of course...
import ClassInsideSWC;
public class MyClass extends ClassInsideSWC
{
public function MyClass()
{
super();
}
}
}
Besides, I don't want to (I can't, in fact) import the SWC by loading it with Loader
class.
Well, someone knows a way to link to the SWC using only ActionScript Code?
Edited
Just to add more info about the problem, I'll showcase my scenario with more details...
I have a class SubClass
that wil be independent from the rest.
It will extend a class SuperClass
that is inside the SWC/SWF...
This SWC/SWF have the whole framework. I can't compile every class inside a single SWF. Every part of my framework is a SWF apart and will be downloaded by Loader class on runtime.
Sadly, @frankhermes answer won't work. That method won't download the classes and won't allow me to extend or use other classes inside the SWC.
If I setup the library path this becomes possible...
A possible correction on Sean Fujiwara's answer:
[Embed(source="SWFWireDecompiler.swc", mimeType="application/octet-stream")]
public var SWC:Class;
might need to be:
[Embed(source="SWFWireDecompiler.swf", symbol="ClassInSWC")]
public class ClassInSWC
{
....
}
EDIT: as a follow-up after the comments, this is another attempt at getting an acceptable answer:
package
{
import flash.display.Sprite;
public class SWCTest extends Sprite
{
public function SWCTest()
{
var extended:ExtendedCrumbs = new ExtendedCrumbs();
}
}
}
[Embed(source="../swfs/assets.swf", symbol="assets.Crumbs")]
class CrumbsInSWC
{
}
class ExtendedCrumbs extends CrumbsInSWC
{
public function ExtendedCrumbs()
{
super();
}
// override something here
}
Sadly it only works with swf files, not with swc's because you can't use symbol="..."
inside Embed statements when using a swc. But the code above does compile. Place the swf file anywhere in your project and adjust the source path inside the Embed statement.
Hope this is still of some use to you! Frank
Why do you say "This line won't work, of course..."? You're almost right, just missing a few things.
[Embed(source="SWFWireDecompiler.swc", mimeType="application/octet-stream")]
public var SWC:Class;
Then you can turn get the data as a ByteArray:
var data:ByteArray = new SWC();
精彩评论