2 Replies Latest reply on Nov 21, 2013 6:20 AM by iSofia

    How to Load & Display Image

    iSofia

      Hello Everyone.

      I am typing with very green fingers, so, please excuse the question. Learning from examples, I have been trying to load and display an image in ActionScript. This is from the original example that I am working on:

       

      ...

      ...

      var bmd2:BitmapData = bmd.clone();

      var infoBM:Bitmap = new Bitmap(bmd2);

      var back:MovieClip = new MovieClip();

      back.name = "back";

      back.rotationX = -90;

      var bSurface:MovieClip = new MovieClip();

      bSurface.y = int(...

      bSurface.z = int(...

      bSurface.addChild(infoBM);

       

      var overlay:Sprite = new Sprite();

      overlay.graphics.beginFill(...);

      overlay.graphics.drawRect(0, 0, bSurface.width, bSurface.height);

      overlay.graphics.endFill();

      bSurface.addChild(overlay);

      back.addChild(bSurface);

       

      var tf:TextField = new TextField();

      tf...

      tf...

      tf...

      bSurface.addChild(tf);

      ...

      ...

       

      I am trying to place an image onto the bSurface instead of the text block, as above. So far, I've come up with:

       

      var iSprite:Sprite = new Sprite();

      var iMatrix:Matrix = new Matrix();

      var bmData:BitmapData;

      bmData = new BitmapData(surface.width, surface.height, true, 123);

       

      var loader:Loader = new Loader();

      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

      loader.load(new URLRequest("c:\pixlr.png"));

      function onComplete (event:Event):void

        {

          bmData = Bitmap(LoaderInfo(event.target).content).bitmapData;

        }

       

      iMatrix.tx = 0;

      iMatrix.ty = 0;

      iSprite.graphics.beginBitmapFill(bmData, iMatrix, false, true);

      iSprite.graphics.drawRect(0, 0, surface.width, surface.height);

      iSprite.graphics.endFill();

       

       

      surface.addChild(iSprite);

       

      ...and:

       

      var bmData:BitmapData;

      bmData = new BitmapData(surface.width, surface.height, true, 123);

       

       

      var loader:Loader = new Loader();

      var location:URLRequest = new URLRequest("c:\pixlr.png");

      loader.load(location);

      bmData = Bitmap(loader.content).bitmapData;

       

       

      surface.addChild(bmData);

       

      but to no success. I've been failing miserably for a days now, and would greatly appreciate some help.

       

      Thanking you in advance,

       

      Sofia.