I’m getting a strange exception from s:Label in Flex 4.1. I have a parent (extending BorderContainer) which has a s:Label in it.
In the parent constructor I have:
label = new Label();
label.setStyle("color", "Red");
label.setStyle("fontSize", 20);
Later the label’s text (only on character) is set, it is positioned and added with addElement(). Everything was OK until I started implementing resizing of the parent component. In order to place the label on the correct location, I moved its positioning to updateDisplayList():
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
...
label.x = width - 10;
label.y = height - 10;
}
When resizing the parent, if the size becomes too small, I get the following exception:
ReferenceError: Error #1069: Property -1 not found on __AS3__.vec.Vector.<flash.display::DisplayObject> and there is no default value.
at spark.components::Label/truncateText()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Label.as:1246]
at spark.components::Label/http://www.adobe.com/2006/flex/mx/internal::composeTextLines()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Label.as:485]
at spark.components.supportClasses::TextBase/updateDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\supportClasses\TextBase.as:684]
at mx.core::UIComponent/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8709]
at mx.managers::LayoutManager/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:663]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:736]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]
As I said, the label contains only one character and I don’t need any truncation. Furthermore, when I get the exception, there is still some blank space for the label.
I tried :
label.maxDisplayedLines = 1;
But this didn’t solve the problem. I’ve even tried falling back to the mx Label and setting truncateToFit to false, but I get the same exception when making the parent too small.
Any ideas will be appreciated. Thanks in advance! 🙂
Update:
I’ve tested this with a Group-based custom component and the problem persists. The strange thing is that if I remove the label with removeElement() in the start of the resize operation, I get the same exception. This is valid even if I set the label reference to null, hoping to have it garbage collected.
Is there a reason you’re not setting your label as being
right="10"instead? It’s a style so you’ll need to set it like that. It’ll work as long as your parent is using absolute layout.As for the truncate text, I do believe there is a way to disable that (probably truncate=”false”);