5 Replies Latest reply on Oct 28, 2008 10:45 AM by Handycam

    Problem getting image size

    Handycam Level 1
      I am loading an image into an image component dynamically on component creation. The images are all different sizes for each instantiation of this component. I am trying to set the size of the component to match the size of the image. I have tried a couple of ways, and am now doing it with the attached code.

      However, the object is always larger than the image, which is causing me problems. I have tried removing the minHeight/minWidth, but then nothing shows at all. Any ideas appreciated, this is the last bug I have to fix...

        • 1. Re: Problem getting image size
          m_hartnett Level 3
          Have you tried using the Event.COMPLETE event instead of the FlexEvent.DATA_CHANGE.
          • 2. Problem getting image size
            Cesare Rocchi Level 2
            Is the image loaded when you try to access itemImage.measuredWidth or height?
            If not you'll have to create a image Loader and attach the resize of your component to the Event.COMPLETE event, so that you are sure that you can read the actual measure of the image.
            • 3. Re: Problem getting image size
              Level 7

              "Handycam" <webforumsuser@macromedia.com> wrote in message
              news:ge7f06$mvi$1@forums.macromedia.com...
              >I am loading an image into an image component dynamically on component
              > creation. The images are all different sizes for each instantiation of
              > this
              > component. I am trying to set the size of the component to match the size
              > of
              > the image. I have tried a couple of ways, and am now doing it with the
              > attached code.
              >
              > However, the object is always larger than the image, which is causing me
              > problems. I have tried removing the minHeight/minWidth, but then nothing
              > shows
              > at all. Any ideas appreciated, this is the last bug I have to fix...

              This doesn't completely address your problem, but might help with the layout
              problems you're having:

              http://flexdiary.blogspot.com/2007/10/undocumented-image-control-properties.html

              HTH;

              Amy


              • 4. Re: Problem getting image size
                m_hartnett Level 3
                I forgot to mention that I don't believe that the measuredWidth/Height or the width/height is available at the complete event time.

                You would either use contentWidth / contentHeight or use
                var r : Rectangle = imageItem.getRect(imageITem) to get the dimensions.
                • 5. Re: Problem getting image size
                  Handycam Level 1
                  Thanks mHartnett, that was it!

                  In the init function, changed the event listener to:
                  itemImage.addEventListener(Event.COMPLETE, setSize);

                  And then the handler:

                  private function setSize(e:Event):void {
                  this.width = itemImage.contentWidth;
                  this.height = itemImage.contentHeight;
                  }

                  Made my day!