1 Reply Latest reply on Feb 21, 2009 2:05 PM by Newsgroup_User

    Enforce Aspect Ratio w/r/t measurement/layout

    IanPMcC
      I've been trying to figure out a way to make a Flex component that enforces its aspect ratio whenever its sized and laid out. Think of a component representing a playing card: The card could be displayed at any size, but its aspect ratio should always be the same. It seems like this ought to be enforceable through the measurement and.or layout process, but I'm having a hard time.

      Here's what I've tried so far: I've created a base class that inherits from Canvas and overrides measure() with the attached code.

      I then inherit an MXML component from this base class into which I build the various content and behaviors. The expectation I had was that if I then put my MXML component into a parent canvas and set, for instance, the height to be 100% of the parent, that the width should be adjusted according to the height of the window and re-laid-out with respect to the changing height when the parent container resizes.

      Does anyone have any thoughts? Am I "doing it wrong"?

      Ian
        • 1. Re: Enforce Aspect Ratio w/r/t measurement/layout
          Level 7

          "IanPMcC" <webforumsuser@macromedia.com> wrote in message
          news:gnpd75$2lh$1@forums.macromedia.com...
          > I've been trying to figure out a way to make a Flex component that
          > enforces its
          > aspect ratio whenever its sized and laid out. Think of a component
          > representing a playing card: The card could be displayed at any size, but
          > its
          > aspect ratio should always be the same. It seems like this ought to be
          > enforceable through the measurement and.or layout process, but I'm having
          > a
          > hard time.
          >
          > Here's what I've tried so far: I've created a base class that inherits
          > from
          > Canvas and overrides measure() with the attached code.
          >
          > I then inherit an MXML component from this base class into which I build
          > the
          > various content and behaviors. The expectation I had was that if I then
          > put my
          > MXML component into a parent canvas and set, for instance, the height to
          > be
          > 100% of the parent, that the width should be adjusted according to the
          > height
          > of the window and re-laid-out with respect to the changing height when the
          > parent container resizes.
          >
          > Does anyone have any thoughts? Am I "doing it wrong"?

          Are you doing anything in updateDisplayList to make sure that you're
          changing the layout in response to the new measurement?