AS3: Fabrication templates/snippets for FlashDevelop

I’d like to share a few snippets and templates that are essential in working with the Fabrication framework in Flash Develop:


SNIPPETS:

process - reflexive notification via namespaces
proxy - proxy injection
reactToClick - reactTo object clik
respondTo - reflexive notification interests

Download snippets


STANDARD TEMPLATES:

 Class.as.fdt
 Class.as.fdt.wizard
 Empty File.txt.fdt
 Event.as.fdt
 Font Library.as.fdt
 Interface.as.fdt
 Namespace.as.fdt

FABRICATION TEMPLATES:

 AsyncFabricationCommand.as.fdt
 AsyncMacroCommand.as.fdt
 FlashApplication.as.fdt
 FlashMediator.as.fdt
 FlexMediator.as.fdt
 Proxy.as.fdt
 Service.as.fdt
 SimpleCommand.as.fdt
 SimpleFabricationCommand.as.fdt

Download all templates


Module in module and ApplicationDomain problem

During creation of multiCMS (next version of myCMS) in fabrication some problems occured.
MultiCMS is content managment system based on few independent modules.
Flow of application:

  • App -> SiteModule  -> UnitModule

App loads SiteModule and it loads UnitModule. Mechanism of loading is identical.
There are moduleProxy and unitProxy. Code looks similar in both, like this:

public function loadModule():void {

  module = new FlexModuleLoader();
  module.addEventListener(
        FabricatorEvent.FABRICATION_CREATED,
        moduleCreated
  );
  module.loadModule();

}
private function moduleCreated(
                        event:FabricatorEvent):void{

  event.target.removeEventListener(
       FabricatorEvent.FABRICATION_CREATED,
       moduleCreated
  );
  // send App.MODEL_LOAD notification
  // to ALL instances of class SiteModule
  // with moduleVO as Body
  routeNotification(
       App.MODEL_LOAD,
       moduleVO,
       "ModuleVO",
       "SiteModule/*"
  );
}

And problem was that after routing notification to “SiteModule/*” I couldn’t get notification body using:

    var vo:UnitVO = note.getBody() as UnitVO;

Every casting was finished with

    vo = null

in output. However what’s interesting I could read any child from note using this:

    var address:String = note.getBody()["address"]
    // or
    var wid:String = note.getBody()["wid"]

Problem was finally solved! In response to my mail author of Fabrication (Darshan Sawardekar) wrote:

“The problem you are facing looks related to Flash player sandboxing. The UnitVO class definition is present in the parent swf and as a result unavailable at the time of casting within the submodule.
If yours modules are all going to come from the same domain then you can try setting the application domain to the current domain so the sandbox of the module swf is the same as the parent.”

Solution:

public function loadModule():void {

  module = new FlexModuleLoader();
  // ##### SOLUTION #######
  module.applicationDomain =
     new ApplicationDomain(
            ApplicationDomain.currentDomain
     );
   // ##### END OF  SOLUTION #######
  module.addEventListener(
        FabricatorEvent.FABRICATION_CREATED,
        moduleCreated
  );
  module.loadModule();

}
private function moduleCreated(
                        event:FabricatorEvent):void{

  event.target.removeEventListener(
       FabricatorEvent.FABRICATION_CREATED,
       moduleCreated
  );
  // send App.MODEL_LOAD notification
  // to ALL instances of class SiteModule
  // with moduleVO as Body
  routeNotification(
       App.MODEL_LOAD,
       moduleVO,
       "ModuleVO",
       "SiteModule/*"
  );
}

Hope will help!