Flex 中静态变量的初始化顺序导致错误

发布于 2024-11-06 17:40:05 字数 1551 浏览 2 评论 0原文

我有一个由第三方开发人员为我的应用程序编写的组件,并正在尝试集成它,但我发现了一个错误,它看起来要么是编译器错误,要么是 Flex 和静态变量的工作方式有问题,我不知道。

基本上,我有这样的:

public class ModeChangeController {
    public static const DISPLAY_MODE:String = "DisplayMode";

}


public class Events {       
    public static const DISPLAY_MODE:String = "DisplayMode";

    public static function myStaticFunction( viewState:String = null):void {
        //Empty
    }
}



<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer /*snip*/ >

    <fx:Script><![CDATA[
        import mypackage.sub1.ModeChangeController;
        import mypackage.sub2.Events;

        private function showInitialView():void {
            // Variant 1
            Events.myStaticFunction( Events.DISPLAY_MODE);

            // Variant 2
            Events.myStaticFunction( ModeChangeController.DISPLAY_MODE);
        }
    ]]></fx:Script>
}    

如果我使用//V2(即注释掉V1),应用程序启动时会出现错误(某些文本字段不可编辑且不包含文本),但使用//V1而不是V2,它可以工作美好的。如果我注释掉两者,那也可以正常工作(我没有遇到 TextField 错误)。

我花了一段时间才弄清楚是那个 static const String 导致了问题,但我仍然不确定为什么或者是否有什么我可以做的,除了将 DISPLAY_MODE 移动到事件(这就是我现在已经完成了,但这不是一个特别好的解决方案)。

日志中没有错误。我的 BorderContainer 代码中的包含顺序并不重要。我用谷歌搜索“as3/flex 静态初始化顺序”,但没有找到任何东西。

有谁知道问题是什么?

说明: showInitialView() 永远不会被调用。在另一个错误出现之前它不会到达那里。仅仅有 V2 线就会导致问题。

更新:我已经解决了 TextInput 字符串不显示的问题:事实证明,添加组件导致 Tahoma 字体不显示。但是,将字体粗细设置为粗体可以解决该问题,或者切换到 Arial。话虽如此,原来的问题仍然存在,因为当我在没有 V2 的情况下运行它时,它发现 Tahoma 具有正常的字体粗细。

I've got a component written for my app by a third party developer and am trying to integrate it, but I've found a bug that seems like it's either a compiler bug, or there's something with how Flex and static variables work that I wasn't aware of.

Basically, I have this:

public class ModeChangeController {
    public static const DISPLAY_MODE:String = "DisplayMode";

}


public class Events {       
    public static const DISPLAY_MODE:String = "DisplayMode";

    public static function myStaticFunction( viewState:String = null):void {
        //Empty
    }
}



<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer /*snip*/ >

    <fx:Script><![CDATA[
        import mypackage.sub1.ModeChangeController;
        import mypackage.sub2.Events;

        private function showInitialView():void {
            // Variant 1
            Events.myStaticFunction( Events.DISPLAY_MODE);

            // Variant 2
            Events.myStaticFunction( ModeChangeController.DISPLAY_MODE);
        }
    ]]></fx:Script>
}    

If I use //V2 (i.e. comment out V1), a bug occurs at the startup of the application (some TextFields are uneditable and contains no text), but with //V1 and not V2, it works fine. If I comment out both, that also works fine (I don't get the TextField bug).

It took me a while to figure out that it was that static const String that was causing the issue, but I'm still not sure why or if there's something I can do about it except for just moving the DISPLAY_MODE to Events (which is what I've done at the moment, but it's not a particularly nice solution).

There are no errors in the log. The order of the includes in my BorderContainer code doesn't matter. I've googled for "as3/flex static initialization order" but haven't found anything.

Does anyone know what the problem is?

Clarification: showInitialView() never gets called. It doesn't get there before the other bug shows up. Just having the V2 line there causes the problem.

Update: I've fixed my problem with the TextInput strings not showing: Turns out that adding the component caused the Tahoma font to not show up. However, setting the font-weight to bold fixed that problem, or switching to Arial. With that said, the original question still stands, because when I ran it without V2, it found Tahoma with normal font-weight.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_蜘蛛 2024-11-13 17:40:05

这不是静态字符串。我自己测试了一下没有问题。我对您的问题表示怀疑,因为无论如何加载应用程序时都会创建闪存静态变量,并且该变量可用。

我相信这个问题与静态变量无关,而是与其他导致错误的原因有关。根据您的描述,您似乎没有调试 Flash Player 的版本。获取它,逐行调试您的应用程序,看看问题是什么。

It's not the static string. I tested it myself without a problem. I was skeptical of your issue since the flash static vars would get created when the application is loaded no matter what and the variable would be available.

I believe the problem has nothing to do with the static var but with something else causing an error. It seems that you don't have a version of Flash Player debug by your description. Get it, debug your application line by line and see what the problem is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文