Skip to main content
November 21, 2013
Question

How to Load & Display Image

  • November 21, 2013
  • 1 reply
  • 438 views

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.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 21, 2013

The first thing you need to reconcile is whether you plan to be working with AS2 or AS3.  You have posted in the AS1/2 forum, but your code is all AS3.  If you truly intend to be working with AS3 then you should repost in the AS3 forum.

http://forums.adobe.com/community/flash/flash_actionscript3?view=discussions

Also make sure your publish settings are set to AS3.

If the intentions is to work with AS2 then you need to redo all of the code to be AS2 code.

November 21, 2013

Sorry; that's how much I know. Reposted to the AS3 thread. Thank you.