Thanks Ian, very interesting. Thanks everyone - good discussion.
Jason Merrill Bank of America Instructional Technology & Media · GCIB & Staff Support L&LD Interested in Flash Platform technologies? Join the Bank of America Flash Platform Developer Community Interested in innovative ideas in Learning? Check out the Innovative Learning Blog and subscribe. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: Thursday, November 20, 2008 5:49 PM To: Flash Coders List Subject: Re: [Flashcoders] get class by definition - or something like that To be honest, I don't know - but I suspect flash.utils.getDefinitionByName() is an alias for ApplicationDomain.currentDomain.getDefinition(). Whereas you can also use getDefinition() to retrieve class definitions from within other ApplicationDomain objects - such as loaded Flex modules. Essentially ApplicationDomains are all about code segregation. You remember how in AS2 if you loaded in a second SWF none of its class definitions would overwrite the ones in the loading movie i.e. it 'inherited' the classes of the parent? i.e. if you had a class called myapp.ClassA in both the movie doing the loading and the movie getting loaded, the first definition encountered would be the one that won. A pain if the movie you're loading in was compiled later, say, with a different version of ClassA. In AS3 in the flash.display.Loader class (or Flex ModuleManager or various other loading classes) you can specify different ApplicationDomains to use for the .swf you're loading in. It's almost like namespacing. If you pass null i.e. the default, from memory that means that the loading .swf gets loaded into a _child_ ApplicationDomain i.e. gets all the parent classes, but none of the new classes are directly instantiable in the parent movie. From memory again, I think that's the same as saying new ApplicationDomain(ApplicationDomain.currentDomain), the latter creating a child domain of the current one. If you pass ApplicationDomain.currentDomain, the loading .swf gets all the parents classes and the new classes it loads are instantiable in the parent movie. If you pass new ApplicationDomain(), the loading .swf is completely isolated. It has its own versions of all classes, and won't accidentally inherit definitions from the parent. This is just for the purposes of direct use of the class/package name i.e. new com.mypack.ClassA(). However, you can get to different class definitions (even different definitions of class with the same name/package as each other) by using getDefinition() on the appropriate ApplicationDomain. I hope that makes sense! My only irritation with it - currently - is that the Flex framework doesn't support running inside a completely separate ApplicationDomain. So loading a Flex .swf into a self-contained ApplicationDomain just doesn't work; which is a shame, as it would have meant that running a Flex 2 app inside a Flex 3 app was perfectly viable or vice versa (useful for legacy; also useful for the project I'm working on at the moment which has one set of CSS in the parent app, a different set in the child...). Apparently that's on the cards to be fixed for Gumbo. That was probably far more detail than you wanted. :-D Ian On Thu, Nov 20, 2008 at 10:26 PM, Merrill, Jason <[EMAIL PROTECTED]> wrote: > Ian and David - interesting. So what is the difference between getDefinition > and getDefinitionByName? > > What I ended up using was this, which works well: > > var ClassReference:Class = > getDefinitionByName("people."+_associates[_associateCount]) as Class; > var instance = new ClassReference(); > > If I need it to be cast as the class it subclasses, like a MovieClip, so it > can be added to the stage, I do: > > addChild(MovieClip(instance)); > > is there any particular reason to use getDefinition instead? At first > glance, seems to accomplish the same thing. > > Jason Merrill > Bank of America Instructional Technology & Media · GCIB & Staff > Support L&LD > > Interested in Flash Platform technologies? Join the Bank of America Flash > Platform Developer Community > Interested in innovative ideas in Learning? Check out the Innovative > Learning Blog and subscribe. > > > > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David > Hershberger > Sent: Thursday, November 20, 2008 5:22 PM > To: Flash Coders List > Subject: Re: [Flashcoders] get class by definition - or something like that > > You want ApplicationDomain.getDefinition(className: String) > and also ApplicationDomain.hasDefinition(className: String) is handy. > > Dave > > On Thu, Nov 20, 2008 at 1:52 PM, Merrill, Jason < > [EMAIL PROTECTED]> wrote: > >> Refersh my memory. What was the name of that AS3 class method to get a >> class definition from a string? Something like >> getObjectByDefinition("MyClass") or something like that, but that's not it. >> Our proxy server is down and I can't Google it, and the help docs are no >> help. >> >> Basically, I'm tring to remember the AS3 method to dynamically instantiate >> a class from a string definition - i.e. >> >> var ClassDefinition:Class = getClassByDefinition("Apple"); >> var newClassInstance:* = new ClassDefinition(); >> >> Something like that, I've done it before, I just can't find the syntax or >> remember the method. >> >> Jason Merrill >> Bank of America Instructional Technology & Media · GCIB & Staff >> Support L&LD >> >> Interested in Flash Platform technologies? Join the Bank of America Flash >> Platform Developer Community >> Interested in innovative ideas in Learning? Check out the Innovative >> Learning Blog and subscribe. >> >> >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders