Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to Load & Display Image

Guest
Nov 21, 2013 Nov 21, 2013

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.

TOPICS
ActionScript
621
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 21, 2013 Nov 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);

Translate
Community Expert ,
Nov 21, 2013 Nov 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 24, 2013 Nov 24, 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2013 Nov 24, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines