1 Reply Latest reply on Aug 27, 2008 10:44 PM by Newsgroup_User

    Self Sizing Text

    Alex_Chamberlain
      Hi,

      I am quite new to Flex, but want to size some text according to the size of its containing canvas using the following function:

      function resizeText():void {
      var fontMetrics = t_preview.getLineMetrics(0);
      while ((t_preview.textWidth < ca_frame.width) && (t_preview.textHeight < ca_frame.height)) {
      preview_fontSize = preview_fontSize+1;
      t_preview.validateNow();
      fontMetrics = t_preview.getLineMetrics(0);
      trace(preview_fontSize);
      trace(t_preview.textHeight);
      trace(fontMetrics.height);
      }

      while (((t_preview.textWidth > ca_frame.width) || (t_preview.textHeight > ca_frame.height)) && preview_fontSize > 0) {
      preview_fontSize = preview_fontSize-1;
      t_preview.validateNow();
      trace(preview_fontSize);
      }
      }

      The top while loop goes infinate and gets stuck at with a text height of 144.3. Any ideas why??

      Thanks,

      Alex