View Full Version : [Advanced] AS3 Game decomposition into separate swf's
shogo
June 4th, 2007, 06:38 AM
Hello,
I'm looking for a good design how to split the big project into separate swf's.
I'm using AS3. FlashDevelop IDE.
I would like to have main login in core.swf, GUI logic in gui.swf all graphics in separate swf's and ect...
But here is the problem in coding. When I load one swf into some Loader i don't know exactly what function and classes that swf has... I have to switch to that swf code and copy function names to be able to call them correctly. It would be great to have something like references in .NET. After attaching dll you know what is inside of it.
Thanks for suggestions.
pingnak
June 4th, 2007, 03:17 PM
Well... you never know that. The knowledge about the swf files involved is implicit, not explicit. It's assumed you KNOW what was in the thing you imported before you call it.
You could use the 'interface' keyword to manufacture interface declarations for things that your external swf files must implement. At least there's a slightly better chance of detecting problems at compile time instead of runtime.
You could use 'Embed' to bind your swf file to a Class and then make an instance of it.
[Embed(source = "mystuff.swf", symbol="swfsymbol")]
protected static const stuff_Class:Class;
public const stuff:MovieClip = new stuff_Class()
I personally use a preprocessor on my code to do that 'automagically', and build arrays of resources. It allows some nifty language extending constructs, but probably isn't for everyone. It also has an 'External Makefile' for MS Visual Studio .Net, so it can be used with various .Net versions as the IDE.
http://flex2cpp.sourceforge.net/
You can also deal with building 'swc' files and linking them in with the right mxmlc parameters.
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=projects_035_32.html
tecknoize
June 15th, 2007, 03:36 PM
You could use the getDefinition function from the ApplicationDomain class. Check that in the docs. Basically you can get a class definition (a Class Object) with a string. For example :
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest("your.swf");
loader.addEventListener(Event.COMPLETE, onLoad);
loader.load(request,context);
private function onLoad(evt:Event){
var yourClass:Class = loader.contentLoaderInfo.applicationDomain.getDefi nition("YourClassName") as Class;
var myInstance:Object = new yourClass();
}
There's some other ways too, like with the flash.utils.getDefinitionByName function. Have fun with the Docs!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.