Skip to main content
November 21, 2013
Answered

How to Load & Display Image

  • November 21, 2013
  • 3 replies
  • 660 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 days now, and would greatly appreciate some help.

Thanking you in advance,

Sofia.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kglad

what are you trying to do?

if you're only trying to load an image (pixlr.png), use a relative path and something like:

var loader:Loader=new Loader();

loader.load(new URLRequest("pixlr.png"));  // put the png in the same directory with your fla and published files.  you can move it after you get this simplest example working

addChild(loader);

3 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 21, 2013

what are you trying to do?

if you're only trying to load an image (pixlr.png), use a relative path and something like:

var loader:Loader=new Loader();

loader.load(new URLRequest("pixlr.png"));  // put the png in the same directory with your fla and published files.  you can move it after you get this simplest example working

addChild(loader);

November 25, 2013

Hello kglad, and thank you very much for THE SOLUTION. I tried many variations of your suggestion from the web, but none of them worked for some reason. Yours, on the other hand, worked like a charm AS IS. My sincerest gratitude, truly.

Thank You, Merci, Danka, Spasibo, Gracias, Arigato, Gamsa, and Shukran!

PS: I looked half of them up, just for you. 

kglad
Community Expert
Community Expert
November 25, 2013

your welcome, bitte, don't know that one, denada, doitashimashite,don't know and don't know.