theDeSilva.com Andrew de Silva

Width and Height for Dynamic Image in Flex

July 16th, 2008 · No Comments · Flash, Flex

Recently I was working on a Flex project and realize upon having my project on the live server , I couldn’t retrieve the height and width property of my loaded image by doing below

var img:Image = new Image();
img.source = "image.jpg"
trace(img.height);
trace(img.width);

The trace statement above will just show 0 for both width and height. Of course after a few hours of searching Google for a solution I realized on the livedocs documentation for Image has the property contentWidth and contentHeight which provides the height and width of the image loaded.

var img:Image = new Image();
img.source = "image.jpg"
trace(img.contentHeight);
trace(img.contentWidth);
Share and Enjoy:
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Facebook
  • Google

Tags: ····