Posted By

forchid on 05/11/09


Tagged

loader as3 Context


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

spastic
vkord


Loader Context


 / Published in: ActionScript 3
 

URL: http://www.kirupa.com/forum/showthread.php?p=2120340

  1. /*
  2. When loading an SWF into another SWF you have 3 options for the placement of the loaded SWFs definitions:
  3.  
  4.   * new partitioned domain: create a new separated domain for the loaded SWFs definitions to live that will separate it completely from those definitions within the loading SWF.
  5.   * current domain: load the definitions into the current application domain of the loading SWF. This will not overwrite existing definitions but it will add new definitions to those within the current application domain of the SWF doing the loading.
  6.   * child domain (default): load the definitions into a new application domain that is a child of the application domain of the loading SWF. This will not affect the current application domain of the loading SWF but it will force the loaded SWF to use any duplicate definitions in the parent over its own
  7.  
  8.  
  9. You specify application domains for loaded content within a LoaderContext (flash.system.LoaderContext) instance. This instance is then passed to the load() method of Loader (Loader.load()). For the domain of the current SWF, you can use ApplicationDomain.currentDomain ().
  10.  
  11. */
  12.  
  13. // child SWF uses parent domain definitions
  14. // if defined there, otherwise its own
  15. var childDefinitions:LoaderContext = new LoaderContext();
  16. childDefinitions.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
  17.  
  18. // child SWF adds its unique definitions to
  19. // parent SWF; both SWFs share the same domain
  20. // child SWFs definitions do not overwrite parents
  21. var addedDefinitions:LoaderContext = new LoaderContext();
  22. addedDefinitions.applicationDomain = ApplicationDomain.currentDomain;
  23.  
  24. // child SWF domain is completely separate and
  25. // each SWF uses its own definitions
  26. var separateDefinitions:LoaderContext = new LoaderContext();
  27. separateDefinitions.applicationDomain = new ApplicationDomain();
  28.  
  29. // set loader context in load()
  30. myLoader.load(request, separateDefinitions);
  31.  
  32.  
  33. var NewClass:Class = ApplicationDomain.currentDomain.getDefinition( "myClass" ) as Class;
  34. var newClassInstance:* = new NewClass();

Report this snippet  

You need to login to post a comment.