开发者

Creating a .swc - why don't interfaces work, when classes do?

开发者 https://www.devze.com 2023-01-17 21:37 出处:网络
I\'m making a game which loads map .swfs at runtime. The maps will contain graphics and code, which can both vary from map to map. I\'ve decided to make all the maps implement an interface, so they ca

I'm making a game which loads map .swfs at runtime. The maps will contain graphics and code, which can both vary from map to map. I've decided to make all the maps implement an interface, so they can all be used in the same way by the game. I'm using a .swc to contain the interface, like in this page.

I can get classes to work in the .swc, but not interfaces!

I'm using Flash cs5, and flashdevelop for editing, in AS3. Here's how I've been doing it:

1- create map.fla with a symbol called Map, and a Map.as:

public class Map extends MovieClip {
    public function test():void {
        trace("woohoo");
    }
}

2- in Flash, right click the Map symbol and choose "export SWC..." and also "export SWF...".

3- create a new .fla and flashdevelop project called Loader in a new folder, an开发者_如何学编程d copy in the .swf and .swc created in 2

4- in flashdevelop, right click the swc and choose "add to library"

5- in flash, actionscript settings -> lirbary path, add swc and set Link Type: External

Now in Loader.as I can access the Map class after loading in map.swf:

public class Loaderoo extends MovieClip {

    public function Loaderoo() {
        var loader:Loader = new Loader()
        loader.load(new URLRequest("map.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
        // var map:Map = new Map(); // this would throw a VerifyError 1014
    }

    private function loaded(e:Event):void {
        var map:Map = new Map();
        addChild(map);
        map.test(); // now it has loaded the class - traces "woohoo"
    }
}

So far so good. But if I try

public class Map extends MovieClip implements IMap {
    ...

and

private function loaded(e:Event) {
        var map:IMap = new Map();
        ...

it doesn't work! I get "VerifyError: Error #1014: Class IMap could not be found." Why oh why? If anyone can help I'd be grateful.


You need to have the interface IMap stored in the swc. Try exporting the whole fla as swc and not only the map symbol.

In Flash: Flash > Publish Settings >Flash> check the Export SWC box.

Now publish the swf and use the resulting swc in FlashDevelop.

Also, maybe it will help if you would include the library completely in FlashDevelop

For this see issue no 2 here: http://flashontherocks.com/2010/12/13/flashdevelop-resolved-issues/

Good luck!

0

精彩评论

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