If I am creating say a input field through MXML
, I can set the width to 100%
. But I cannot seem to do this at runtime through ActionScript.
This works:
<mx:TextInput ... width="100%" />
This wont compile, says width is a number, not a string:
var textinp:TextInput = new TextInput();
someContainer.addChild(textinp);
textinp.width = "100%"
How can I set 100%
as the size on a component created at runtime via ActionScript?
You just need to use the percentWidth
attribute, instead of the width
attribute.
So, the third line in your code would be :
textinp.percentWidth = 100;
This tripped me up for awhile, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With