2012-11-07 46 views
0

所以我试图存储和加载数据,但由于某些原因我得到错误代码1046 - type was not found or was not a comile-time constant1120 - access of undefined property SharedObject与actionscript3中的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

像往常一样,这个错误意味着你还没有导入的类定义。将此添加到AS文件的导入部分:

import flash.net.SharedObject;