0

I've got a spark button on a screen, and I'm updating the label dynamically using actionscript like so:

discount.label = this.data.SelectedDiscount.discount + "%";

The problem is that the new label text is truncated, even though there is room for it.

Initially the label in the button is blank:

Black button label

Then after I change the label with the code above it looks like this, when it should say "30 %":

Truncated text

However, if I then click the button it updates the display and renders it correctly:

Correct rendering of the label

I've tried all the various invalidate and validate methods, playing with the button width and more, all to no avail. If the initial label is wider, with a value like "-------" then it works ok, but unfortunately a string of whitespace doesn't do the trick. I don't really want a string of "0%" or "00%" for usability reasons so is there any easy way to get this working properly?

Preferably I'd like to avoid having to fake a mouse click just to achieve this.

zero323
  • 322,348
  • 103
  • 959
  • 935
Matt Lacey
  • 8,227
  • 35
  • 58
  • That shouldn't happen. Something must be off in your skin class. Can you show us some code? – RIAstar Nov 08 '12 at 00:01
  • discount is an instance of the Button class, correct? Have you tried invalidatingSize() on the labelDisplay skin part of the Button? ( http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/Button.html#SkinPartSummary ). A runnable sample demonstrating the problem would help here. – JeffryHouser Nov 08 '12 at 00:01
  • Discount is a button in the mxml like so: "" — I should have mentioned that this is inside an item renderer. – Matt Lacey Nov 08 '12 at 00:20
  • Can you show your itemRenderer code? – JeffryHouser Nov 08 '12 at 00:27

1 Answers1

1

Thanks to @www.Flextras.com's guidance, I got this working by calling the invalidateSize() method on the button's skin rather than on the button itself, i.e.:

discount.skin.invalidateSize();
Matt Lacey
  • 8,227
  • 35
  • 58