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, and 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.