Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between getDefinition and getDefinitionByName in AS3

Can somebody explain what is the difference between getDefinitionByName and getDefinition inA AS3?

When I load an external SWF I can't use getDefinitionByName because I get an Error #1065.

But using externalSWF_ContentLoaderInfo.applicationDomain.getDefinition works OK.

So, why getDefinitionByName doesn't find the className? I mean, if the definition is inside the applicationDomain of the loaded SWF, why is not in the main SWF too? (I'm using Flex).

Offtopic: I can't create new tags so I can't add the tags getDefinition and getDefinitionByName :(

like image 973
Enrique Avatar asked Jul 02 '11 20:07

Enrique


1 Answers

getDefinition is a method of an ApplicationDomain which returns a definition of a class, namespace or function.

getDefinitionByName is a package-level function from flash.utils which returns a Class object that you can use to instantiate new Objects. The definition must already be loaded somewhere in your ApplicationDomain.

The reason you can't make getDefinitionByName with an external SWF is that it is loaded into a separate ApplicationDomain. Your second example works because you are targeting the correct ApplicationDomain. To make your first example work you must load the external SWF into your current ApplicationDomain like this:

var request:URLRequest = new URLRequest("externalSWF.swf");
var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;
var loader:Loader = new Loader();
loader.load(request,context);

This works because it passes the current ApplicationDomain as a property of the loader context.

like image 55
shanethehat Avatar answered Nov 17 '22 02:11

shanethehat