5 Replies Latest reply on Aug 28, 2007 5:21 PM by SymTsb

    AS3 Library and Linkage

    aib42
      Hi, I have a few questions regarding the Library and the linkage of its assets in AS3/CS3.

      The only way I know of using an external image (e.g. a PNG file) in Flash/AS is:
      Add the image to the library, give it some linkage - name: "my_image", class: "BitmapData" (cannot seem to change this)
      Then from within AS:
      var bd:BitmapData = my_image(16, 16);
      var b:Bitmap = new Bitmap(bd);
      ...

      This approach has a few problems. First of all, you have to specify the image's width and height from within the code.
      Secondly, it's impossible to pass "my_image" around. If you pass it as a parameter to a function (I've only tried the constructor of another class, i.e. "new MyClass(my_image);" but I don't think that's the problem) the constructor will become what I can only guess to be something like a copy constructor, expecting one parameter of type my_image$, whatever that is.

      All my code is dynamic; I don't use the stage, and I use the library only when necessary.
      I do not want to probe the library assets using the Library class; that is hardly portable. Plus,

      var bd:BitmapData = my_image(Library.something.findItemByName("my_image").something.width, Library.something.findItemByName("my_image").something.height);

      looks like an overkill.

      Now the Flex approach here is very good; embedded images become instantly instantiatable Bitmap objects; but Flex has its own limitations.

      Any suggestions?
        • 1. Re: AS3 Library and Linkage
          kglad Adobe Community Professional & MVP
          the width and height parameters are irrelevant in your constructor and you should be using bd for the instance reference, not my_image (which is the class, not linkage).
          • 2. Re: AS3 Library and Linkage
            SymTsb Level 2
            Use the URLLoader class in conjunction with the Bitmap and BitmapData classes. This will allow you full dynamic control over the assets and they'll never have to be in the library although perhaps in a folder relative to the flash app or swf....
            • 3. Re: AS3 Library and Linkage
              aib42 Level 1
              Woah, they really are irrelevant.
              I could've sworn they resized the image.... Then again, there's Flex Builder 2, Flex 2 SDK, Flash CS3, FL components and MX components swirling all inside my head!

              The Loader classes would be my second choice, though I really wanted to embed the images inside the SWF file and not load them externally.

              Thanks
              • 4. Re: AS3 Library and Linkage
                kglad Adobe Community Professional & MVP
                if you really want them in your library, import them to your library. i'm not aware of any limitations of using library bitmaps vs loading them.
                • 5. Re: AS3 Library and Linkage
                  SymTsb Level 2
                  There aren't limitation by any means. I am the type of person who prefers to keep as much dynamic as I can. Unless I'm developing a GUI for an application I will use pure AS to get stuff like this done.