Flex 中的 mxml 继承。 “instanceof”如何工作和“是”?
早些时候,我使用了以下结构:
Canvas -> Screen1
Canvas -> Screen2
当我觉得应用程序中需要通用逻辑时,我下一步会做:
Canvas -> Screen
Screen -> Screen1
Screen -> Screen2
因此,当我尝试将它应用到我的代码中时,
if(child is Screen){
return child.localToGlobal(new Point()).x;
}
它不起作用! 当我在调试器中看到时,child 的类型为“Screen2”,但“child is Screen”向我返回 false(“child instanceof Screen”也返回 false)。 当我应用编译器密钥:“-keep- generated-actionscript”时,我可以看到 Screen2- generated.as 并且它包含
public class Screen3 extends screens.Screen
提前感谢 抱歉我的英语不好=)
Earlier i used following structure:
Canvas -> Screen1
Canvas -> Screen2
When I feel need in common logic in my application I do next:
Canvas -> Screen
Screen -> Screen1
Screen -> Screen2
So when I try to apply it in my code
if(child is Screen){
return child.localToGlobal(new Point()).x;
}
It is not works!
When I see in debugger, child have type "Screen2", but "child is Screen" returns false to me (and "child instanceof Screen" too).
When I apply compiler key: "-keep-generated-actionscript" I can see Screen2-generated.as and it's contains
public class Screen3 extends screens.Screen
Thanks in advance
Sorry for my ugly english=)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于这个特定的名称 - 已经有一个名为 Screen 的类(在 flash.display 中 - http://livedocs.adobe.com/flex/3/langref/flash/display/Screen.html),Flex 检查它是否是原始屏幕的实例。
您可以尝试两件事:
1)将您的 Screen 类重命名为 CustomScreen 并重试。
2)通过引用完整路径来检查子级是否是您的类的实例,例如。
if(子项是screens.Screen)
I think the issue is with this specific name - there already is a class called Screen (in flash.display - http://livedocs.adobe.com/flex/3/langref/flash/display/Screen.html), and Flex checks if it's an instance of the original screen.
You can try two things:
1) Rename your Screen class to CustomScreen and try it again.
2) Check if the child is an instance of your class by referencing it full path eg.
if (child is screens.Screen)