1 Reply Latest reply on Dec 13, 2007 4:43 PM by David_F57

    Dynamic Image width/height

    ClubPetey Level 1
      I am trying to build a specialize layout control, and the control works with all child controls except the Image and SWFLoader. The reason is that they have dynamic width/height and I cannot find the right event to trap to get it.

      In the case of the Image, I've tried the COMPETE, UPDATE_COMPLETE, and RENDER events but in the case of dynamic content (scaleContent = false) the width/height properties of the Image are not set at the times these event fire. I thought about using contentWidth/contentHeight however this will not work for two reasons:

      1. I do a lot of queries against the width/height properties, and would create a lot of IFs in the code (or calls to a function) and this does not seem elegant

      2. Many user-developed Image controls the width != contentWidth because they have added borders on the Image

      There HAS to be an event that is fired once the control is measured and scaled. in reading the Docs (and some other forums) it's supposed to be one of the three i've used, although the docs and forums do not agree on which one.

      Any thoughts?
      -pete
        • 1. Re: Dynamic Image width/height
          David_F57 Level 5
          Not sure what you are trying to do this is a simple example of getting the true image size after loading an image in a renderer.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="102" height="102" borderThickness="0"
          paddingLeft="1" paddingTop="1" paddingRight="1" paddingBottom="1"
          verticalAlign="middle" horizontalAlign="center"
          verticalScrollPolicy="off" horizontalScrollPolicy="off" backgroundAlpha="1.0">

          <mx:Script>
          <![CDATA[
          import mx.managers.DragManager;
          import mx.core.DragSource;
          import mx.events.DragEvent;
          import mx.containers.Canvas;
          private var AR: Number;

          private function setdim(): void
          {
          data.width = myimage.contentWidth;
          data.height = myimage.contentHeight;
          AR = data.width/data.height;
          //data.aspect = AR;
          if (AR > 1)
          {
          data.aspect = "L";
          }
          else
          {
          data.aspect = "P";
          }
          }



          ]]>
          </mx:Script>
          <mx:Image id="myimage" source="{data.tnpath}" width="100" height="100" verticalAlign="middle" horizontalAlign="center"
          maintainAspectRatio="true" complete="setdim()" />
          </mx:VBox>