1 Reply Latest reply on Aug 4, 2007 6:06 AM by peterent

    sharing custom classes between different projects

      I'm using different projects as modules for a main application. I'm trying to use a custom class to share data between the modules. I've been unable to share the custom data's variables.

      Can this be done?

      Thanks for the help!!

        • 1. Re: sharing custom classes between different projects
          peterent Level 2
          You need to read up on ApplicationDomains. When your main/first SWF has been loaded by the Flash Player it is put into an ApplicationDomain - this is the parent domain. When a Module is loaded it is put into a child domain.

          If your main SWF has a Button defined, and your Module also has a Button defined, the Module's Button definition is ignored - the first class definition loaded wins.

          The parent domain cannot see into the child domain. Any data residing in the Module is not available to the parent and to any siblings because they too are loaded into separate domains.

          Suppose Module wants to use an HBox and the HBox class was not loaded by the main SWF. Now another Module is loaded, it too wants to use HBox. Since the HBox class was loaded by the first Module it will not be loaded by the second Module. However, the second Module won't be able to use the HBox because it resides in a different domain. If the main SWF had loaded the HBox, both children can use it - the Flash Player first searches for a class in the current ApplicationDomain, and if it is not there, goes to the parent domain.

          The same is true for data - the parent domain should load the data so it can be shared by all of the child domains/Modules.

          You can load Modules into the same domain as the parent, but you'll have to read the documentation for that. This has a couple of drawbacks because data loaded by a Module will clobber data loaded by the main SWF, but it can work if you are careful.