Although maybe overkill, to solve the problem I have created a custom component ; a multiline button extending the button component provided with Flex. I guess there may be a number of reasons why you may like to do this, obviously this inherits the properties and methods of the button, for example I have a nice colour change when a user rolls over the text, making it more obvious that this is a link. I could also add some events, such as switching the text once the button has been pressed, providing an indication that the file has been downloaded.
Above: 2 is a normal button; 3 is my shiny multiline button at work (button fill and border alpha is 0)
A quick search in Google brings up Alex's (adobe) blog showing a method for creating multiline radio buttons by extending the radio button class. Essentially ive used this pattern as suggested to apply to the button component, with a few minor changes.
override protected function createChildren():voidI needed to specify that the text field would be the same width (slightly less) than its container: the button, otherwise it reverted to a small default value. The original code "addChild(textField);" wouldn't work for me, producing the error:
{
if (!textField)
{
textField = new NoTruncationUITextField();
textField.styleName = this;
textField.width=this.width-8;
addChild(textField as DisplayObject);
}
1067: implicit coersion of a value of type mx.core:UITextField to an unrelated type Flash.display:DisplayObject
I cast it as a Display object which solved this issue. Although I admit im not entirely sure why I managed to get this error and Alex did not, difference in sdk's or flashplayer?
As far as changes go thats it, so full credit to Alex for providing a nice pattern. This also shows how easy it is to work with Flex with its powerful and customisable/ flexible framework. I can't wait to get stuck in some more...
No comments:
Post a Comment