Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
Adobe Flex SDK 3.2 (Release)
-
None
-
None
-
Affected OS(s): Windows
Affected OS(s): Windows XP
Browser: Internet Explorer 6.x
Language Found: English
Description
Steps to reproduce:
1. Create a LinkBar with a data provider of a ViewStack.
2. Remove each of the items in the viewstack which correctly removes each button on the LinkBar until it is empty.
3. Add a new item to the viewstack, which adds a new button to the LinkBar, but is unselected.
4. Click the new button.
Run the code example below. Click the Remove button until all items have been removed. Then add a new item and click the linkbar button. The error below is thrown.
Actual Results:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.skins.halo::HaloBorder@3c803d1 to mx.controls.Button.
at mx.controls::LinkBar/hiliteSelectedNavItem()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\LinkBar.as:525]
at mx.controls::LinkBar/clickHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\LinkBar.as:598]
Looking at the selectedIndex of the LinkBar and ViewStack, when the last item is removed, the selectedIndex is still 0 rather than -1. This seems to cause the LinkBar clickHandler to pass -1 to the LinkBar function hiliteSelectedNavItem which then tries to get the child at index -1
Line 597 of LinkBar.as if (index == selectedIndex)
hiliteSelectedNavItem(-1);
Line 525 of LinkBar.as child = Button(getChildAt(selectedIndex)); // LinkBar passed in a hardcoded -1 from the clickHandler.
Expected Results:
LinkBar should support removing all items and adding new items without throwing an exception. The linkBar selectedIndex should be set to -1 when all items have been removed and incremented when new items are added to the dataProvider.
Workaround (if any):
A workaround was found. When you're adding the first item to the linkbar, add two items, then immediately remove one. This appears to fix the problem but is an ugly hack.
Code Example:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="doCreateComplete()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.controls.Label;
public var STATE_ARRAY:Array = [
,
,
,
,
,
,
];
[Bindable] public var acStates:ArrayCollection = new ArrayCollection(STATE_ARRAY);
private function doCreateComplete():void {
// initialize view stack
for each (var o:Object in STATE_ARRAY)
myLinkBar.selectedIndex = 0;
}
private function addItemToViewStack(label:String, data:String):void
{ var labelCtrl:Label = new Label(); labelCtrl.text = data + " is located in the state of " + label + "."; var box:HBox = new HBox(); box.setStyle("verticalAlign", "middle"); box.setStyle("horizontalAlign", "center"); box.setStyle("borderStyle", "solid"); box.percentWidth = 100; box.label = label; box.addChild(labelCtrl); myViewStack.addChild(box); } ]]
>
</mx:Script>
<mx:ViewStack id="myViewStack" width="400" height="300">
<!-- Canvases added by script -->
</mx:ViewStack>
<mx:LinkBar id="myLinkBar" dataProvider="
"/>
<mx:HBox width="400">
<mx:Button id="addName" label="Add Item" click="
" />
<mx:Label text="label: " />
<mx:ComboBox id="itemLabel" dataProvider="
"/>
<mx:Spacer width="100%"/>
<mx:Button label="Remove Selected" click="myViewStack.removeChild(myViewStack.selectedChild)"/>
</mx:HBox>
</mx:Application>