[英]Flex Error #1009: Cannot access a property or method of a null object reference
[英]Flex Error #1009: Cannot access a property or method of a null object reference
我想在我的 init() 方法中使用一个按钮。
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Test"
creationComplete="init()">
现在,当我尝试用我的按钮做一些事情时,我得到了提到的错误。 我假设它可能还没有加载?
function init():void{
myButton.thisorthat == makes the error.
}
*编辑**该按钮是在 MXML 中创建的,顺便说一句,这并不重要,但这是针对 flex 移动应用程序的。
其实这很重要。 关于 NavigatorContent(假设您的孩子是这些类型容器之一的子集)要记住的一件事是它们的 halo 对应物都将内容创建策略设置为延迟 - 这意味着它创建了视图/视图堆栈的父级最层,但在用户实际导航到该特定孩子之前,它不是孩子。 一种欺骗是将策略设置为“全部”,但更好的方法是实际监听FlexEvent.CONTENT_CREATION_COMPLETE (这是从导航容器的子级广播的)。
例如:
<halo:ViewStack id="setupStack" width="100%" height="100%">
<api:FileSelector width="100%" height="100%" owner="{this}"
enumerationMode="{FileSystemEnumerationMode.DIRECTORIES_ONLY}"
hint="{networkDbAccessHint}" />
<!- this is valid, but not it's children until contentCreateComplete is fired -->
<api:DataImport width="100%" height="100%" owner="{this}" />
</halo:ViewStack>
“FileSelector”和“DataImport”都广播事件(扩展 s:NavigatorContent)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.