动作:制作一个变量`[可绑定]`导致崩溃 [英] ActionScript: making a variable `[Bindable]` causes crashes

查看:443
本文介绍了动作:制作一个变量`[可绑定]`导致崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的单身人士,我使用一个包装全局变量和常量,但只要我做出一些 [可绑定] 我上开始崩溃瓦特/在我的控制台一堆红色文本。

的类型错误:错误#1009:无法访问空对象引用的属性或方法。
    在BrandGlobals $ / GET COLOUR_EVERYTHING_BACKGROUND()[C:\ MyProject目录的\ src \ BrandGlobals.as:14]
    在BrandGlobals $ cinit()
    全球$的init()[C:\ MyProject目录的\ src \ BrandGlobals.as:2]
    在_mainWatcherSetupUtil /设置()
    在主/初始化()[C:\ MyProject目录的\ src \ main.mxml:0]
    在mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2131]
    在mx.managers::SystemManager/initializeTopLevelWindow()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3400]
    在mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3223]
    在mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3069]

BrandGlobals:

 包{
公共final类BrandGlobals {
    [可绑定]公共静态无功COLOUR_EVERYTHING_BACKGROUND:UINT = 0xE010FF;
 

如果我删除 [可绑定] 按钮并转动 VAR 常量有(​​除了不能够设定外此文件的变量的明显的问题)没有问题,但这种不工作。此外,使全班 [可绑定] ,而不是这一个没有工作。当我悬停我把鼠标移到 COLOUR_EVERYTHING_BACKGROUND 的定义,它说:<异常引发的吸气剂>中。 不知道该怎么想到这一点。

我可能已经猜到了,那是因为它没有包,但我在使用其他类似的单具有 [可绑定] 变量,似乎很好地工作。

我从来没有拿到 [可绑定] 妄说。

我使用Flex 3.5 SDK。

我想布赖恩的建议之下,但它给了我pretty的多少同样的错误。我甚至尝试:

  {
    _COLOUR_EVERYTHING_BACKGROUND = 0xE010FF;
    跟踪(无功集。);这里//断点
    bLoadedFerCryinOutLoud =真;
}

[可绑定]私人静态无功_COLOUR_EVERYTHING_BACKGROUND:单元;
私人静止无功bLoadedFerCryinOutLoud:布尔=假;

公共静态函数得到COLOUR_EVERYTHING_BACKGROUND():UINT {
    跟踪(回归一切的背景);
    如果(bLoadedFerCryinOutLoud)
        返回_COLOUR_EVERYTHING_BACKGROUND;
    否则返回0XFFFFFF;
}
 

更重要的是,如果我把一个断点在那个跟踪(无功集。); ,Flash Builder会抱怨说,休息是不可能的,因为没有可执行code那里。

我还注意到,在该调用堆栈,我表明当这种碰撞过程中设置发生,这似乎是一个集 _COLOUR_EVERYTHING_BACKGROUND 。但是,在其设置的唯一的地方是:

 公共静态函数的setBackground(oApp:UBIApplication):无效{
    _COLOUR_EVERYTHING_BACKGROUND = oApp.nBackgroundColour;
}
 

和断点表明,这是从来没有所谓。

解决方案

事实证明,这个问题是分配 COLOUR_EVERYTHING_BACKGROUND 静态常量在code在其他地方,作为一项临时措施。希望我会记住的分配 [可绑定] s到静态常量 s是坏的,如果我不这样做,我会记住的特定含义模糊的反应Flash Builder中具有的意义。我开始呛计算器瓦特/我对神秘的错误消息的问题。

I have this singleton that I'm using as a wrapper for global variables and constants, but as soon as I make some [Bindable] I get a crash on start up w/a bunch of red text in my console.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at BrandGlobals$/get COLOUR_EVERYTHING_BACKGROUND()[C:\MyProject\src\BrandGlobals.as:14]
    at BrandGlobals$cinit()
    at global$init()[C:\MyProject\src\BrandGlobals.as:2]
    at _mainWatcherSetupUtil/setup()
    at main/initialize()[C:\MyProject\src\main.mxml:0]
    at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::childAdded()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2131]
    at mx.managers::SystemManager/initializeTopLevelWindow()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3400]
    at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3223]
    at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3069]

BrandGlobals:

package {
public final class BrandGlobals {
    [Bindable]public static var COLOUR_EVERYTHING_BACKGROUND:uint = 0xE010FF;

If I remove that [Bindable] and turn var to const there's no problem (except the obvious problem of not being able to set the variable outside of this file) but this doesn't work. Also, making the whole class [Bindable] instead of this one didn't work. When I hover my mouse over the COLOUR_EVERYTHING_BACKGROUND definition, it says "<exception thrown by getter>". 'Don't know what to think about that.

I might have guessed it was because it has no package, but I'm using another similar singleton which has [Bindable] variables and seems to work fine.

I never did get that [Bindable] twaddle.

I'm using the Flex 3.5 SDK.

I tried Brian's suggestion below, but it gave me pretty much the same error. I even tried:

{
    _COLOUR_EVERYTHING_BACKGROUND = 0xE010FF;
    trace("Var set."); //Breakpoint here
    bLoadedFerCryinOutLoud = true;
}

[Bindable]private static var _COLOUR_EVERYTHING_BACKGROUND:uint;
private static var bLoadedFerCryinOutLoud:Boolean = false;

public static function get COLOUR_EVERYTHING_BACKGROUND():uint {
    trace("Returning EVERYTHING background");
    if (bLoadedFerCryinOutLoud) 
        return _COLOUR_EVERYTHING_BACKGROUND;
    else return 0xFFFFFF;
}

What's more, if I put a breakpoint at that trace("Var set.");, Flash Builder complains that a break is not possible, because there is no executable code there.

I also noticed that in that call stack that I'm shown when this crash happens during a set and it seems to be the one that sets _COLOUR_EVERYTHING_BACKGROUND. But the only place where it is set is:

public static function SetBackground(oApp:UBIApplication):void {
    _COLOUR_EVERYTHING_BACKGROUND = oApp.nBackgroundColour;
}

and breakpoints indicate that this is never called.

解决方案

It turns out that the problem was assigning COLOUR_EVERYTHING_BACKGROUND to a static const elsewhere in the code, as a temporary measure. Hopefully I'll remember that assigning [Bindable]s to static consts is bad and if I don't, I'll remember the meaning of that particular cryptic reaction Flash Builder had. I'm starting to choke StackOverflow w/my questions about cryptic error messages.

这篇关于动作:制作一个变量`[可绑定]`导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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