The function flash.utils.getDefinitionByName has been discussed in various other places (amongst others here and of course in the documentation), but it took a bit of a mental jump to use it as the solution for the problem that linked library instances without a class are not known inside FDT.Suppose we have a library item with a linkage id of “square”, and we decide not to attach a class to it. Flash CS3 reminds us that it will create one for us, and if we code inside the Flash IDE, we can happily write: var s:Sprite = new square(); addChild(s);However, FDT will show an error, because it doesn’t have a clue what you’re talking about. To solve this, use getDefinitionByName("square"), as shown in the following example:

  2. package {
  3.     import flash.display.MovieClip;
  4.     import flash.display.Sprite;
  5.     import flash.utils.getDefinitionByName;
  7.     public class Application extends MovieClip {
  9.         private static const LINKAGE_SQUARE:String = "square";
  11.         public function Application () {
  12.             var s:Sprite = new (getDefinitionByName(LINKAGE_SQUARE))();
  13.             addChild(s);
  14.         }
  15.     }
  16. }
25 Nov, 2007, 22:48 o'clock

Add your own comment or set a trackback

Currently 1 comment

  1. Comment by Jankees

    Just what I was looking for 🙂

Add your own comment

Follow comments according to this article through a RSS 2.0 feed


This is a Flickr badge showing public photos from AcidCats. Make your own badge here.