返回 Flex Air 中新复选框的值

发布于 2024-08-09 18:50:48 字数 774 浏览 4 评论 0原文

我正在尝试将设置保存到 XML 文件,并在选中或未选中该复选框时设置相关数据。

private static function createXMLData():void 
{
    prefsXML = <preferences/>;
    prefsXML.application.@windowsstart = Application.application.SettingsPage.settingWindowsStart.selected;
    prefsXML.application.@mintosystray = Application.application.SettingsPage.settingMinToSysTray.selected;
    //prefsXML.windowState.@x = stage.nativeWindow.x;
    //prefsXML.windowState.@y = stage.nativeWindow.y;
    prefsXML.saveDate = new Date().toString();
}

但是,当我运行它时,由于第一次运行,复选框上没有设置任何值,因此我收到错误。

TypeError: Error #1009: Cannot access a property or method of a null object reference.

好吧,我认为这就是错误的含义,它无法获取尚未设置的内容的详细信息..那么我如何让它进行检查,如果什么都没有那么它显然是“假”。

谢谢。

I am trying to save settings to an XML File and setting the relevant data if the check box is checked or not.

private static function createXMLData():void 
{
    prefsXML = <preferences/>;
    prefsXML.application.@windowsstart = Application.application.SettingsPage.settingWindowsStart.selected;
    prefsXML.application.@mintosystray = Application.application.SettingsPage.settingMinToSysTray.selected;
    //prefsXML.windowState.@x = stage.nativeWindow.x;
    //prefsXML.windowState.@y = stage.nativeWindow.y;
    prefsXML.saveDate = new Date().toString();
}

However when i run it, there is no values set on the check boxes due to the first time running and therefore i get an error.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

well i assume that is what the error means, it cannot get details of something that is not set yet.. so how would i get it to check and if nothing then it is obviously a "false".

Thank you.

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

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

发布评论

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

评论(5

荆棘i 2024-08-16 18:50:48

看起来您正在应用程序构建完成之前(因此在 UI 组件存在之前)访问数据。尝试在调度 applicationComplete 事件后的某个时间调用此代码。

<mx:Application ... applicationComplete="onApplicationComplete(event)">
  <mx:Script>
    private function onApplicationComplete(event:Event):void {
      createXMLData();
    }
  </mx:Script>
  ...
</mx:Application>

It looks like you are accessing the data before the application construction is complete (and therefore before the UI components exist). Try calling this code sometime after the applicationComplete event is dispatched.

<mx:Application ... applicationComplete="onApplicationComplete(event)">
  <mx:Script>
    private function onApplicationComplete(event:Event):void {
      createXMLData();
    }
  </mx:Script>
  ...
</mx:Application>
只有影子陪我不离不弃 2024-08-16 18:50:48

您正在尝试访问复选框的 selected 属性,但错误表明复选框对象本身为 null - 因此没有要获取的 selected 属性。

因此,看起来该复选框根本不存在。您需要先创建它。

You are trying to access the selected property of the checkbox, but the error is saying that the checkbox object itself is null - hence there is no selected property to get.

So, it doesn't look like the checkbox exists at all. You will need to create it first.

佼人 2024-08-16 18:50:48

需要认识到的一件事是,一旦您在复选框和某个布尔字段之间创建数据绑定,该复选框就应该始终具有一个值。

One thing to realize is that the checkbox should always have a value once you create a data binding between the checkbox and some boolean field.

骄兵必败 2024-08-16 18:50:48

如果不查看更多代码,我无法真正确定,但似乎 SettingsPage 是类的名称,而不是类的实例。

I can't really be sure without looking at more code, but it seems like SettingsPage is the name of the class, not the instance of the class.

只有一腔孤勇 2024-08-16 18:50:48

您可以通过检查复选框轻松解决这些复选框可能存在或可能不存在的事实:

if(Application.application.SettingsPage["settingWindowsStart"])
    prefsXML.application.@windowsstart = Application.application.SettingsPage.settingWindowsStart.selected;
else
 prefsXML.application.@windowsstart = false;

这使得您提到的假设是,如果组件不存在,则将 windowsstart 设置为 false。
或者,您也可以使用 try catch 块:

try {
    prefsXML.application.@windowsstart = Application.application.SettingsPage.settingWindowsStart.selected;
}
catch(e:Error) {
    trace(e.getMessage());
    prefsXML.application.@windowsstart = false;
}

这将有助于解决问题,但我建议至少尝试首先了解问题发生的原因。

You can easily work around the fact that the checkboxes may or may not exist by checking for them:

if(Application.application.SettingsPage["settingWindowsStart"])
    prefsXML.application.@windowsstart = Application.application.SettingsPage.settingWindowsStart.selected;
else
 prefsXML.application.@windowsstart = false;

This makes the assumption you mentioned of setting windowsstart to false if the component does not exist.
Or alternatively you can use a try catch block:

try {
    prefsXML.application.@windowsstart = Application.application.SettingsPage.settingWindowsStart.selected;
}
catch(e:Error) {
    trace(e.getMessage());
    prefsXML.application.@windowsstart = false;
}

This will help get around the problem but I'd recommend at least making an attempt to understand what the problem is happening in the first place.

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