Embedding/importing SWC at compile-time in ActionScript, without setting a library path

吃可爱长大的小学妹 提交于 2019-12-24 12:28:01

问题


Hail, Stack!

I'm having a little trouble figuring out how to import a SWC file directly in ActionScript, without 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...


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/5284985/embedding-importing-swc-at-compile-time-in-actionscript-without-setting-a-libra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!