【问题标题】:Unable to find whats wrong with this code for adobe air无法找到 adobe air 的此代码有什么问题
【发布时间】:2012-11-04 18:13:37
【问题描述】:

第一次使用 adobe air 应用程序。不知道下面的代码有什么错误。它没有提醒“否”值。

请看,saveData()getData() 来自这个question

            function check(){
                var d1 = getData('item1');
                var d2 = getData('item2');
                if (d1 && d2) {
                    alert('yes');
                } else {
                    alert('no');
                }
            }   

            saveData('item1','value1');
            saveData('item2','value2');
            // I know that its ridiculous to save the data and then reset it.
            // But This is how the main code works. sorry.
            air.EncryptedLocalStore.reset();
            check();

【问题讨论】:

    标签: actionscript-3 air adobe


    【解决方案1】:

    当您评估表达式 d1 && d2 时,您正在执行 逻辑与 operator

    && (逻辑与) — 如果表达式 1 为假或可以转换为假,则返回表达式 1,否则返回表达式 2。

    大概当您测试if(d1 && d2) 时,条件为真,在加载两个实例时提醒“yes”

    只有在失败时,例如 d1d2null 时才会发出此警报“否”

    【讨论】:

      【解决方案2】:

      在检查之前,您要从 ELS 中清除数据:

      flash.data.EncryptedLocalStore.reset(): 清除整个 加密本地存储,删除所有数据。

      我不确定您为什么要这样做,或者它是如何为您工作的(正如您声称的那样),但如果您说它是必需的,而不是必需的。假设这确实有效并且不会给您带来问题,您可能希望修改此逻辑,因为它非常奇怪。

      此外,传递给条件的参数应输入为字符串,条件应检查这些字符串的长度是否不为零。

      试试这个:

      function check():void
      {
          var d1:String = getData("item1");
          var d2:String = getData("item2");
      
          if (d1.length && d2.length)
          {
              alert("yes");
          }
          else
          {
              alert("no");
          }
      }   
      
      saveData("item1","value1");
      saveData("item2", "value2");
      
      // This is ghetto!
      air.EncryptedLocalStore.reset();
      
      check();
      

      为避免错误和问题,您应严格键入代码。

      猜你喜欢
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      相关资源
      最近更新 更多