2012-04-16 37 views
1

我开始放弃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中解决的组件?

感谢

+1

看起来不像范围问题,更多的时机。组件为空时使用哪个事件? (在'initialize'事件之前还是之后?) – alxx 2012-04-16 06:54:59

+0

alxx是对的;当你尝试第一次访问mainCalendar时,可能是mainCalendar还没有创建。即使在初始化被触发之后,也可能是Flex尚未创建它(例如,如果组件不可见) – Eduardo 2012-04-16 08:07:21

+0

如果你说你不应该访问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

回答

1

(创建应答如此这个问题可以被标记为回答)
通常,当对组件的引用为空且不应该时,这意味着组件尚未被创建。这可能发生在应用程序initialize事件之前,或者组件的父项不可见且未经过验证。

+0

我同意,并且,对我而言,我在调用问题函数之前与视觉进行交互的日历实例必须是(我在想)与原始日历不同的日历实例,但这是一个主题另一个问题。谢谢。 – 2012-04-18 13:41:22