Aha! Finally got it all working. Enjoy a mod system if you'd like.
Host.zip contains the classes the host (whatever's loading the mods) uses.
Mod.zip contains the classes the mod uses to contact the host.
Again, requires AS3 Signals library because I'm too lazy to make new classes. Or you could make events if you want portability.
And of course an example usage below.
Host:
public class Main extends Sprite {
public function Main():void {
ModLoader.ON_READY.add(onReady);
ModLoader.loadMod(File.applicationDirectory.nativePath + File.separator + "mods" + File.separator + "myMod1.swf");
ModLoader.loadMod(File.applicationDirectory.nativePath + File.separator + "mods" + File.separator + "myMod2.mod");
ModLoader.loadMod(File.applicationDirectory.nativePath + File.separator + "mods" + File.separator + "myMod3.whateverFileExtensionYouWant");
}
private function onReady():void {
ModLoader.onReady.remove(onReady);
ModLoader.ON_MESSAGE.add(onMessage);
ModLoader.addChannel("myChannel");
ModLoader.addChannel("myChannel2");
ModLoader.startMods();
for (var i:uint = 0; i < ModLoader.numMods; i++) {
ModLoader.send(i, "myChannel", ["Here", "Have", "An", "Array", "Because", "Why", "Not?"]);
}
}
private function onMessage(modNum:uint, data:ModData):void {
trace("Message from mod #" + modNum + " on channel " + data.channelName);
trace("Data: " + JSON.stringify(data.data));
}
}
Mod:
public class Main extends BaseMod {
public function Main():void {
if (Worker.current.isPrimorial) {
stage.nativeWindow.close();
}
ON_CHANNEL_MESSAGE.add(onMessage);
addChannel("myChannel");
addChannel("myChannel2");
}
private function onMessage(data:ModData):void {
trace("Message from host on channel " + data.channelName);
trace("Data: " + JSON.stringify(data.data));
sendChannel(data.channelName, {stuff:"You can out anything you want", stuff2:"In the data argument", stuff3:"It doesn't matter"});
sendChannel("myChannel2", {data:["Ohai", "How", "Are", "You?"]});
}
}
Both of these examples are assuming they're made in AIR, so if they aren't stuff like stage.nativeWindow won't work and all that happy fun stuff. Also I don't think traces work in a mod when loaded from the host, though I might be wrong.
When sending ByteArrays, make sure the shareable property on them is true.
mods are given the same permissions and folders/etc as the host, so think of the mod as being the host when doing stuff like File.applicationDirectory and such.
In some versions of FlashDevelop Workers are a bit broken.
Other than that, yeah, it seems to work quite well which is a big surprise :D
(If you do decide to try it out, please tell me if there's bugs D:)