1 Reply Latest reply on Nov 9, 2007 9:51 AM by G V B

    Adding images from separate class

    G V B
      I'm trying to dynamically add images from a separate class, called from the main document class. I am using CS3.

      My main class is as follows:

      package imageReader {
      import flash.display.*;

      public class LoadTest extends Sprite {
      public function LoadTest () {
      // constructor
      var thumbnail = new XMLImage();
      }
      }
      }

      This calls a separate class in the same package named XMLImage. The XMLImage constructor dynamically loads an image, created through the Bitmap/BitmapData/addChild() process (seen in part, below):

      largeImage = Bitmap(_loader.content);
      largeImageData = largeImage.bitmapData;
      addChild(largeImage);

      If I call XMLImage directly, as my main document class, it works, and the image appears on the stage. So, there does not appear to be a problem with the process of loading images.

      However, if I call it through another class, as above, it still works (via trace), but the image does not appear on the stage.

      I'm sure I'm missing something simple here, but... I've been unable to figure it out.

      Thanks...
        • 1. Re: Adding images from separate class
          G V B Level 1
          Ok -
          This works...
          Adding a method that sets a variable with the root in the XMLImage class:

          thumbnail.setRoot(root); // sets rootlocation in XMLImage

          Then I use the addChild method on the variable set to root.
          rootlocation.addChild(largeImage);
          Works...

          However, this seems like a bit of a hack. Is there a better way to accomplish this?