Flex的错误#1009:无法访问空对象引用的属性或方法 [英] Flex Error #1009: Cannot access a property or method of a null object reference

查看:328
本文介绍了Flex的错误#1009:无法访问空对象引用的属性或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的初始化使用按钮()方法。

I am trying to use a button in my init() method.

<?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()">

现在,当我尝试做一些与我的按钮,我收到提到的错误。我猜想,也许它没有加载?

Now when I try to do something with my button I get the error mentioned. I am assuming maybe it has not loaded yet?

function init():void{
     myButton.thisorthat == makes the error.
}

*的修改的** 在MXML创建BTW按钮 这不是问题,但这是一个柔性的移动应用程序。

*EDIT** The button is created in MXML btw Not that it matters, but this is for a flex mobile app.

推荐答案

实际上,它的确实的事情。有一件事有关NavigatorContent(假设你的孩子是这些类型的容器的一个子集)以及它们的光环同行要记住的是他们都设定为递延内容创建策略 - 这意味着它创建父大部分观点/ ViewStack的层的,但不是其子,直到用户实际已经导航到该特定子。其中的作弊的是,该政策设置为所有,但更好的方法是实际侦听 FlexEvent.CONTENT_CREATION_COMPLETE ,而不是(这是从导航的孩子播放容器)。

Actually it does matter. One thing about NavigatorContent (assuming your children are a subset of one of these types of containers) to remember along with their halo counterparts is they all have a content creation policy set to deferred - meaning it creates the parent most layer of the view / viewstack, but not it's children until the user has actually navigated to that particular child. One cheat is to set the policy to 'ALL', but the better way is to actually listen for the FlexEvent.CONTENT_CREATION_COMPLETE instead (this is broadcast from the child of the navigation container).

例如:

<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)。

Both 'FileSelector' and 'DataImport' broadcast the event (extends s:NavigatorContent).

这篇关于Flex的错误#1009:无法访问空对象引用的属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆