You may be suffering from some issues trying to add the FlashCart system as a member of a parent swf. There is actually a few ways to remedy this. This article will cover them.
First off you can ONLY load this into a AS3 SWF file. This includes anything compiled in Flex3, Flash CS3 or Flash CS4.
##1st choice
1) loading an external SWF and allowing it to self control itself.
First off when loading in the SWF for the cart you actually MUST load Main.swf, not the skin's swf file. The cart's config file will control that part. The thing is that Main.swf depends on a FlashVar given to it through html OR it falls back on a default xml file.
You can either utilize some way to inject a flashVar to the Loader instance telling it where your config.xml file is located.
Or you can have it load the default. The default expected xml file MUST be named "config.xml" and be located adjacent to the embed location. When loading it into a parent the adjacent location would be the same folder Main.swf is located in.
##2nd choice
2) loading an external SWF and forcing you own parameter.
Main.swf doesn't start loading until it has been added to the FlashPlayer's stage instance. This means that it doesn't perform any of the work until you either add the Loader instance to your DisplayList OR when you add the "content" of your Loader instance to the DisplayList.
There is a method typed to the Main.swf called "init( url:String ):void", if you run this method BEFORE adding it to any DisplayList you can stop it from parsing out the FlashVar or falling back on the default xml file.
In this case you could load it as follows:
--------CODE-----------
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadedHandler );
loader.load( new URLRequest("loaction_of_Main.swf") );
function loadedHandler(e:Event):void
{
loader.content.init( "location_of_config.xml" );
this.addChild( loader.content );
}
--------END CODE --------------------
##3rd choice - ADVANCED USERS ONLY
3) The final solution can be done by instantiating your own instance of the cart system. This method is the most difficult method as it requires a lot of work on your end as a coder, and there are a lot of holes in it.
First off, If you instantiate through class type the config file still must be loaded and passed to the instantiated instance of the cart system. It must still point to the flashCartSystem install directory where dbConfig.php is located.
When instantiating it yourself you must load the "skin" instance on your own, or create your own ISkin class and instantiate it. If you either load a premade skin, or instantiate your own custom one, it must be passed to the cart as an ISkin instance.
Essentially what you'd do is import the "FlashCart" project into your own project. Load the config.xml file of your choice from wherever, then create an ISkin (either through loading or instantiation), finally create an instance of FlashCart() and run FlashCart.init( configXML, skinInstance )
add the Skin to your DisplayList and you're good to go.
If you look in the Main.as file of the FlashCart project you can see how this is actually what is done by the application. Main.as is merely the access point of the program. It performs a very simple task as described here:
wait to be added to stage OR wait for init() method to fire
figure out location of config XML file and load it in
from the config file figure out the Skin location and load it
instantiate a FlashCart instance
pass it the skin to manage (model-view-control design)
pass the FlashCart system the config file (this lets it know where the install directory of the php is)
Finally add the Skin to the stage. |