• Русская Версия
  • Constantiner

Constantiner's blog

RIA: Adobe Flex, Adobe AIR, Flash-platform, ActionScript, MXML, Microsoft Silverlight, WPF, Sun JavaFX
  • Home
  • Contact
  • Log in

Truncate Labels in percent width containers

It is abundant problem to truncate Label control in percent-width container. For example we have the following code:

XML:

<?xml version="1.0" encoding="utf-8"?>
  <mx:Application
      horizontalAlign="left"
      xmlns:mx="http://www.adobe.com/2006/mxml"
      layout="vertical">
      <mx:Style>
          Box
          {
              border-style: solid;
              border-color: #000000;
              border-thickness: 1;
          }
      </mx:Style>
      <mx:Box
          width="10%">
          <mx:Label
              width="100%"
              text="Lalalalalalallallallalallalallallalalalallalalalal" />
      </mx:Box>
      <mx:Box
          width="10%">
          <mx:Spacer
              height="20" />
      </mx:Box>
  </mx:Application>

The result is:

This text is replaced by the Flash movie.

As we can see the first container takes more than 10% (because the second container is exactly 10% width). As far as we know truncateToFit property is true by default and there is no way to make the first container 10% width too except to extend Label component:

  1. package com.riapriority.controls
  2. {
  3.     import mx.controls.Label;
  4.  
  5.     public class AutoTruncatedLabel extends Label
  6.     {
  7.         public function AutoTruncatedLabel()
  8.         {
  9.             super();
  10.         }
  11.  
  12.         override protected function measure():void
  13.         {
  14.             super.measure();
  15.             if (truncateToFit)
  16.             {
  17.                 measuredMinWidth = 0;
  18.                 measuredWidth = NaN;
  19.             }
  20.         }
  21.     }
  22. }

Lets modify our application to see the difference:

XML:

<?xml version="1.0" encoding="utf-8"?>
  <mx:Application
      horizontalAlign="left"
      xmlns:mx="http://www.adobe.com/2006/mxml"
      layout="vertical"
      xmlns:controls="com.riapriority.controls.*">
      <mx:Style>
          Box
          {
              border-style: solid;
              border-color: #000000;
              border-thickness: 1;
          }
      </mx:Style>
      <mx:Box
          width="10%">
          <controls:AutoTruncatedLabel
              width="100%"
              text="Lalalalalalallallallalallalallallalalalallalalalal" />
      </mx:Box>
      <mx:Box
          width="10%">
          <mx:Label
              width="100%"
              text="Lalalalalalallallallalallalallallalalalallalalalal" />
      </mx:Box>
  </mx:Application>

The result is the following:

This text is replaced by the Flash movie.

As we can see the first label is truncated and the first container width is 10% now. To expand the first container to full text width just set our Label’s truncateToFit property to false.

Hope it helps! :)

Bookmark this article at …

  • By Konstantin Kovalev
  • February 24th, 2008
  • Posted in Flex, Tips and tricks
  • 1685 views
  • 2 feedbacks »
  English (US)  
 

Debugging event handlers in MXML gotchas

Everybody knows how difficult to debug event handlers in MXML attributes. So if we try to debug creationComplete event of our simple application with Flex Builder’s debugger we’ll fail:

XML:

<?xml version="1.0" encoding="utf-8"?>
  <mx:Application  
    creationComplete="helloLabel.text = 'Hello, ' + event.currentTarget"
    xmlns:mx="http://www.adobe.com/2006/mxml"  
    layout="vertical">
    <mx:Label
      id="helloLabel" />
  </mx:Application>

Lets set breakpoint at line 3 and… we can debug Application’s addEventListener (namely Container’s) for subscribing to creationComplete event. It’s not that we need :no:

To debug inline MXML handlers we can use the other way of declarative expressiveness. Lets transform attribute to node:

XML:

<?xml version="1.0" encoding="utf-8"?>
  <mx:Application  
    xmlns:mx="http://www.adobe.com/2006/mxml"  
    layout="vertical">
    <mx:creationComplete>
      <![CDATA[
        helloLabel.text = 'Hello, ' + event.currentTarget;
      ]]>
    </mx:creationComplete>
    <mx:Label
      id="helloLabel" />
  </mx:Application>

Just set breakpoint at line 7 and voilà. We can examine event’s object properties in debugger’s Variable View.

The only problem is intellisense for event property, event object type (and properties) etc. in Flex Builder (tested in FB 3 beta 3). As the final release of Flex Builder will be very soon I’m looking forward for this behavior will be fixed.

Hope it helps!

Special thanks to Eldar ‘Pirrest’ Prilutskiy for pointing me this.

Bookmark this article at …

  • By Konstantin Kovalev
  • February 22nd, 2008
  • Posted in Flex, Flex Builder, Tips and tricks
  • 369 views
  • 3 feedbacks »
  English (US)  
 

Flex 3 beta 2 family is out!

Adobe AIR logoCool fresh news, guys! Flex 3 beta 2 with Flex Builder 3 beta 2 and Adobe AIR beta 2 are out on Adobe Labs! :D

Bookmark this article at …

  • By Konstantin Kovalev
  • October 1st, 2007
  • Posted in Flex, Flex Builder, News, Links, Adobe AIR
  • 433 views
  • Send feedback »
  English (US)  
 

Generating get/set methods

Eclipse LogoIf we try to enumerate all the features we wish to see in an ideal IDE our list will be incomplete without code templates. Like in JDT for example. But Flex Builder do not include templates and its little annoying. Mostly in a case of get/set accessors which are essential in ActionScript.

Fortunately I’ve discovered a blog post with Eclipse Monkey usage example. Moreover I’ve found a simple script for get/set accessors generating.

In my case this simple script is not very useful. Most of my get/set methods are bindable and the resulting code is more complex. As a result of my modifications of the original script there are three ones in the archive.

The usage is pretty the same as described:

  • getters-setters.js contains slightly modified original.
  • advanced-getters-setters.js is a generator for get/set accessors with binding.
  • And collection-getters-setters.js is a script for different kind of collections and contains subscribing on COLLECTION_CHANGE event with corresponding handler.
    Just write:

    Code:

    myTest:ArrayCollection
    Then select the pseudo code and run script. Voilà! Fix import and compile.

And there is a list of resources that can help:

  • Installation and usage instructions.
  • Other Installation instructions.
  • Documentation on Aptana site.
  • Eclipse Help reference (after plug-in installed).

Good luck! :)

Bookmark this article at …

  • By Konstantin Kovalev
  • September 27th, 2007
  • Posted in Flex, Flex Builder, Eclipse
  • 165 views
  • 1 feedback »
  English (US)  
 

Flex 3 beta 2 announce

Flex 3 LogoThe guy with enormously enlarged Flex logo also known as Ted Patrick is about to do it again! All of us remember his daily posts about upcoming Flex 3 beta 1. The good news are Flex 3 beta 2 is coming soon!

Every day from Wednesday to next Monday he will covering more and more details. Looking forward for excellent new features :)

Bookmark this article at …

  • By Konstantin Kovalev
  • September 24th, 2007
  • Posted in Flex, Flex Builder, News, Links, Adobe AIR
  • 33 views
  • Send feedback »
  English (US)  
 
  • Constantiner's blog

  • Blog about Rich Internet Applications (RIA) world (Adobe Flex/AIR/Flash, Microsoft Silverlight/WPF, Sun JavaFX) and even more...

  • About Me

    Konstantin Kovalev
    RIA developer, consultant on contract basis, freelancer.

    Location: St.Petersburg, Russian Federation

    Specialization: Adobe Flex, Adobe AIR, Flash platform.

    Russian version is also available in Google Translate.
  • May 2008
    Sun Mon Tue Wed Thu Fri Sat
     << <   > >>
            1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30 31
    • Recently
    • Archives
    • Categories
    • Latest comments
  • Search




  • Categories

    • All
    • Adobe
      • Adobe AIR
      • Flex
        • Flex Builder
    • Eclipse
    • Links
    • Microsoft
      • Silverlight
      • WPF
    • News
    • RIA
    • Sun
      • Java
        • J2EE
        • JavaFX
    • Tips and tricks
    • Utilities
  • Archives

    • February 2008 (2)
    • October 2007 (1)
    • September 2007 (2)
    • More...
  • Want to hire a Flex-developer from Russia?

    Google Groups Beta
    ruflexjobs
    Visit this group
  • XML Feeds

    • RSS 2.0: Posts, Comments
    • Atom: Posts, Comments
    What is RSS?
  • Aggregation

    Aggregated by MXNA
  • User tools

    • Login
    • Register
    • Admin
  • Who's Online?

    • Guest Users: 1
  • Poll

    Are you interesting in Russian Flex programmers?
    • Add an Answer

    View Results

  • Stats

    This blog has 5 posts and 6 comments spanning a range from 09/24/07 to 02/24/08. The total number of words in all posts is 2,336 and the total number of views for individual posts is 7,304.

    Most comments

    • Debugging event handlers in MXML gotchas (3)
    • Truncate Labels in percent width containers (2)
    • Generating get/set methods (1)

    Most views

    • Truncate Labels in percent width containers (1,686)
    • Flex 3 beta 2 family is out! (433)
    • Debugging event handlers in MXML gotchas (369)
    • Generating get/set methods (165)
    • Flex 3 beta 2 announce (33)
    • More...

    Most words

    • Truncate Labels in percent width containers (325)
    • Debugging event handlers in MXML gotchas (223)
    • Generating get/set methods (209)
    • Flex 3 beta 2 announce (58)
    • Flex 3 beta 2 family is out! (20)
    • More...
  • Contents

    • Truncate Labels in percent width containers
    • Debugging event handlers in MXML gotchas
    • Flex 3 beta 2 family is out!
    • Generating get/set methods
    • Flex 3 beta 2 announce
  • Recent comments

    • Konstantin Kovalev on Truncate Labels in percent width containers
    • Arnoud Bos on Truncate Labels in percent width containers
    • Andychou on Generating get/set methods
    • John on Debugging event handlers in MXML gotchas
    • Konstantin Kovalev on Debugging event handlers in MXML gotchas
    • Tom Chiverton on Debugging event handlers in MXML gotchas

powered by b2evolution free blog software


Contact | Powered by b2evolution
Credits: Foppe Hemminga | multiple blogs | web hosts