我开始放弃Flex论坛,所以我要在这里重新发帖,看看事情进展如何。很长时间的潜伏者,第一次海报;-)Flex自定义组件,事件和范围
我陷阱在舞台上的键盘事件和派遣通过框架自定义事件(伴侣,虽然我不知道这是一个重要的问题),但我'米很迷惑的范围。其结构是:
--application(陷阱键盘事件和调度自定义事件
-- mainPanel (receives dispatched events but mainCalendar (a child element)
is null on debugging. Obviously if I try to call a public method on
mainCalendar it errors out, even though it's a child of mainPanel.
However, mainCalendar is NOT null IF I use
FlexGlobals.topLevelApplication.mainPanel.mainCalendar.
Outerdocument and parentDocument do not expose mainCalendar either, BTW
-- mainCalendar (a custom component inside mainPanel with public methods.
Creation policy is 'all' and it's visible and exists long before I
trap any keystrokes at the top level)
可能有人需要一分钟,并解释为什么mainCalendar超出范围时的mainPanel接收自定义事件,即使mainCalendar是mainPanel中的孩子。有没有更好的方式来管理事件,所以我不必总是通过topLevelApplication中解决的组件?
感谢
看起来不像范围问题,更多的时机。组件为空时使用哪个事件? (在'initialize'事件之前还是之后?) – alxx 2012-04-16 06:54:59
alxx是对的;当你尝试第一次访问mainCalendar时,可能是mainCalendar还没有创建。即使在初始化被触发之后,也可能是Flex尚未创建它(例如,如果组件不可见) – Eduardo 2012-04-16 08:07:21
如果你说你不应该访问topLevelApplication,那么你是对的。这正是事件的目的:任何组件都可以监听任何事件。但是因为我不知道你想要做什么,所以我只能指出你[AS中事件处理的基础知识](http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html )。此外,由于您使用的是Mate,因此我猜想它也有一些事件处理功能,所以您可能还想阅读[docs](http://mate.asfusion.com/page/documentation/) 。 – RIAstar 2012-04-16 11:57:01