A customer filed a bug recently about a backwards compatibility issue that they ran into when trying to compile their Flex 3 application in Flex 4. Normally, your application should compile just fine, but, you might run into some behavioral differences between the two releases. However, in the case described in bug SDK-25021, your application won’t even compile! When using the ‘selectedChild’ property for any of the MX Navigators like TabNavigator, ViewStack or Accordion, you will get the following error in Flex 4:
Error: Implicit coercion of a value of type mx.core:INavigatorContent to an unrelated type flash.display:DisplayObject.
myViewStack.removeChild(myViewStack.selectedChild)
This code compiled fine in Flex 3, but, won’t compile in Flex 4. Unfortunately, we had to loosen the type of the selectedChild property to get the MX navigators working with Flex 4 Spark content. The type of selectedChild was ‘Container’, now it is ‘INavigatorContent’. In Flex 4, both the Container and NavigatorContent classes implement INavigatorContent. You will need to make some minor tweaks to your Flex 3 code to have it compiling in Flex 4.
To resolve the compile error, just cast your selectedChild property to a Container. For example, here is the Flex 3 code converted to Flex 4 code:
Flex 3: myViewStack.removeChild(myViewStack.selectedChild)
Flex 4: myViewStack.removeChild(Container(myViewStack.selectedChild))
I hope this makes the migration easier. Good luck!
本文解决了一个Flex3应用在迁移到Flex4时遇到的编译错误问题。当使用‘selectedChild’属性时,Flex4会出现类型不匹配的错误。文章提供了具体的代码示例来演示如何通过类型转换解决此问题。

249

被折叠的 条评论
为什么被折叠?



