让SuperTabNavigator支持NavigatorContent

flexlib已经升级到Flex 4了,最近有用到SuperTabNavigator。我用NavigatorContent作为其子容器,结果出错:TypeError: Error #1009: 无法访问空对象引用的属性或方法。at flexlib.containers::SuperTabNavigator/reorderTabList()[E:\Exercise\Flex\Tutorials\Demo\src\flexlib\containers\SuperTabNavigator.as:1181]。

我花了一点时间解决了修正了这个Bug。打开SuperTabNavigator.as源码,定位到1181行附近。

var child:Container = this.getChildAt(i) as Container;
var obj:Object = new Object();
//setting the type to an empty string bypasses a bug in MenuItemRenderer (or in 
//DefaultDataDescriptor, depending on how you look at it). Try commenting out the
//line and check out the menu items.
obj.type = ";
obj.label = (child.label != ") ? child.label : "Untitled Tab";
obj.icon = child.icon;

原来是将child的类型由NavigatorContent强制转化成Container时失败,child为null,当然无法访问其label属性。在Flex 4中,Container和NavigatorContent都实现INavigatorContent接口,因此只要将child的类型由Container改为INavigatorContent就可以支持NavigatorContent了。

发表评论