Custom Initialization

Overview
You can run custom initialization code in Main both before the site.xml loads, or after the site.xml loads but before Gaia navigates to the first branch. This initialization code can be asynchronous and anything you want. If you're going to load a file or anything else that would take time, you might want to give some feedback to the user to let them know the site is not frozen.



Before The Site XML Loads
To run custom initialization before the site.xml is loaded (such as setting a site.xml path based on a specific language), override the loadSiteXML function in your Main class file.

loadSiteXML
loadSiteXML is what triggers Gaia to load the site.xml, so make sure that if you override it, you call the super method when you're finished. You can do this synchronously or asynchronously. Here is an example of what this looks like synchronously:

AS3
override protected function loadSiteXML:void {     // do whatever super.loadSiteXML; }

AS2
private function loadSiteXML:void {     // do whatever super.loadSiteXML; }



init
After Gaia parses the site.xml and loads the preloader, it calls init. If you override init in your Main class, you can run any code you want before Gaia calls the first goto. It's sort of like a mini hijack. Because the site.xml is loaded and parsed, you have full access to the site tree and initial site variables. This means you could load some custom asset xml and call addAssets to any page instead of using indexFirst.

Do not call super.init.

initComplete
When you're done, you call initComplete. initComplete is called similarly to releaseGaia in the Event Hijacking engine. You can run asynchronous code, like loading a file, before you call initComplete.

Do not override initComplete.

AS3
override protected function init:void {   // do whatever you want initComplete; }

AS2
private function init:Void {   // do whatever you want initComplete; }