actionscript 3中的共享对象问题

时间:2012-11-07 03:08:22

标签: ios actionscript-3 flash adobe

所以我正在尝试存储和加载数据,但出于某种原因,我收到了错误代码1046 - type was not found or was not a comile-time constant1120 - access of undefined property SharedObject

我已导入所需的正确文件。

此代码位于时间轴上的一个框架中,并且应该在用户点击与代码对应的页面时运行。

代码:

import flash.desktop.NativeApplication;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.setInterval;
           // Listen for exiting event.
           NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExit);

           // Also save every 30 seconds.
           setInterval(save, 30*1000);

          // Load data.
           load();


         function onExit(e:Event):void
        {
           save();

        }

        function save():void
        {
                    // Get the shared object.
      var so:SharedObject = SharedObject.getLocal("myApp");

      // Update the age variable.
      so.data['age'] = int(so.data['age']) + 1;

      // And flush our changes.
      so.flush();

      // Also, indicate the value for debugging.
      trace("Saved generation " + so.data['age']);
        }

         function load():void
        {
            // Get the shared object.
      var so:SharedObject = SharedObject.getLocal("myApp");

      // And indicate the value for debugging.
      trace("Loaded generation " + so.data['age']);
        }

1 个答案:

答案 0 :(得分:2)

像往常一样,此错误表示您尚未导入类定义。将其添加到AS文件的导入部分:

import flash.net.SharedObject;