View Full Version : modularizing into multiple .swf files and still sharing variables and functions
coolburn
August 25th, 2007, 04:24 PM
Hello,
I've been pulling my hair out trying to figure this out.
I would like to modularize into three .swf files.
1. boot.swf - this one will take the other two, put them together, and let them share functions and variables
2. api.swf - this would be a set of functions and variables that are used by the third flash file
3. main.swf - this is the main functionality, but it needs to make use of some of the functions and variables in api.swf
The reason I want boot.swf to load them, is so that I can mix and match api's with the main program code being plugged in. But, boot.swf will be the standard file that I start with.
I have gotten as far as getting boot.swf to load main.swf using Loader. However, I can't seem to get main.swf to access anything in boot.swf... let alone access anything in api.swf.
Any assistance is much appreciated!
Thank you!
coolburn
August 25th, 2007, 06:48 PM
I guess a more basic question is this:
If,
1. boot.swf compiles with an external class Api (contained in api.as)
and
2. boot.swf loads a separate main.swf at runtime
then how can main.swf access the functions and variables in boot.swf's Api class?
Right now, boot.swf can use the Api class just fine, and access its variables and functions.
But, main.swf cannot. boot.swf currently loads main.swf like this:
var ldr:Loader = new Loader();
var url:String = "file:///c:/main.swf";
var urlReq:URLRequest = new URLRequest(url);
var addedDefinitions:LoaderContext = new LoaderContext();
addedDefinitions.applicationDomain = ApplicationDomain.currentDomain;
ldr.load(urlReq, addedDefinitions);
addChild(ldr);
Then main.swf runs, but it can't find any references to the Api class.
Thanks!
butcherBaker
August 27th, 2007, 07:14 PM
I'm just learning, and potentially wrong, but I don' t think main.swf can call the methods of Boot by default. I think you'd either have to have the API class also imported into Main at compile time. Otherwise, if it's possible, I suppose you might look into the Access Modifiers of your class, ie, private, public, protected, etc.
or maybe you need to set up methods in Boot that allow the Main swf to tell it what to do, and feed it the info it needs. that's how I've set up my first modular experiment.
butcherBaker
August 27th, 2007, 07:19 PM
hey, look here.
Outside looking in.
http://www.kirupa.com/forum/showthread.php?p=2167721#post2167721
coolburn
August 27th, 2007, 07:49 PM
I was actually able to get this to work. The trick was to pass in the current ApplicationDomain when loading the .swf's. Then they have access to the parent's definitions (and the parent has access to the children's). Then I got hung up for a bit before I realized that to access the external classes, you had to resolve the class by name, and set it to a local variable to use.
That worked pefectly. Now I'm just stuck with the issue that I posted in another thread... which is that even though the initial loading .SWF file is not meant to be visual in any way, it pushes its stage dimensions (and background and framerate) onto whatever SWF files it loads.
So, basically the loaded SWF is forced to inherit those properties from the loader... which is not what I want. Sigh. Oh well, one step at a time. =P
butcherBaker
August 28th, 2007, 12:07 PM
I was actually able to get this to work. The trick was to pass in the current ApplicationDomain when loading the .swf's. Then they have access to the parent's definitions (and the parent has access to the children's). Then I got hung up for a bit before I realized that to access the external classes, you had to resolve the class by name, and set it to a local variable to use.
So if I understand you right, on loading, you provide the parent's application domain & qualified class name to the loaded swf? and this allows the loaded file to call the methods of the parent, which it could not do if it didn't know the class of the parent.
right?
can you show the steps you took to supply the app domain to it please?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.