开发者

How to effectively load SWF libraries?

开发者 https://www.devze.com 2023-01-24 19:13 出处:网络
I am making an AS3 project in FB4. In our workflow, we have artists compile art into SWC files which the I then link as \'Referenced Libraries\' in FB4.

I am making an AS3 project in FB4. In our workflow, we have artists compile art into SWC files which the I then link as 'Referenced Libraries' in FB4.

Then I set the "Link Type" of the SWC files to "external" instead of merged into code. This should create SWFs corresponding to the SWC files in the output folder, right?

This doesn't seem to be the case. I am only seeing one SWF file: the main_app's.

I was trying to make it so that I can use a library manager to load the files dynamically.

I tried extracting the swfs manually, but it seems the main_app still 开发者_如何学Ccompiles all the swcs to itself. I made sure the Link Type was set to external. The file size for the main_app between "external" and "merged to code" seem to be the same.


I've made a simple project in Flash Builder 4 and the only way I got the SWC->SWF happening is by creating a Flex Project instead of an ActionScript Project and selecting "Runtime shared library (RSL)" instead of "External". This is because the Flex framework have some classes that work out the loading of those libraries for you. It also automate the conversion (I should say extraction) process.

Now, if you don't want to create a Flex project just for this, you can extract the SWF yourself. The SWC file format is just a Zip containing a SWF and an XML file describing the content. You can then load dynamically this extracted SWF file using a Loader and setting the correct Application Domain. Here's a snippet of my sample project.

public class Web extends Sprite
{
    public function Web()
    {
        //you will not be able to instantiate classes of your library until it's loaded
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
        loader.load(new URLRequest("library.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));
    }

    protected function onLoadComplete(event:Event):void
    {
        //here you can create instances of classes defined in your library
        new Asset();
    }

}

You might think that's a pretty tedious job to unzip+copy every time your designers update the library. You could automate this process with a script or an Ant file. Unfortunately, unless I'm missing something, it looks like Flash Builder doesn't want you to extend your build process, so you will still need a bit of hand work or completely convert to Ant (or something similar) to build.

Good luck!


From the moment the SWC is added to your Library, you should be able to access the SWC's assets by directly calling their specific class names . There's no need to try to get a SWF and load it with the Loader class. This actually defeats the purpose of using a SWC in the first place!

Let's say that , in your SWC, you have a MovieClip with a class name of GraphicAsset, to create a new instance , you simply do this:

  var mc:MovieClip = new GraphicAsset();

In FB4's folder structure , have a look at your SWC in the Referenced Libraries folder & check the default package, you should see a list of all your assets.

0

精彩评论

暂无评论...
验证码 换一张
取 消