2014-09-27 100 views
-1

出於某種原因,想看看時,如果它的工作,我得到類型錯誤:AS3 - 不能使用SharedObject?

Error #1034: Type Coercion failed: cannot convert "[object SharedObject]1" to flash.net.SharedObject.

這裏是我的代碼:

stop(); 

var savedstuff:SharedObject = SharedObject.getLocal("myStuff"); 

addEventListener(Event.ENTER_FRAME, enterFrameEvent); 

function enterFrameEvent (event:Event){ 
    savedstuff += 1; 
    trace (savedstuff); 
} 

bootoon.addEventListener(MouseEvent.CLICK, clicks); 

function clicks (event:MouseEvent){ 
    gotoAndStop(2); 
} 

回答

0

您需要訪問一個名爲財產數據從共享對象以便在本地保存和加載變量。

var so:SharedObject = SharedObject.getLocal("savedata"); 
var foo:uint = so.data.foo ? so.data.foo : 0; // If there is a foo property then load it, otherwise set it to zero. 
foo++; 

so.data.foo = foo; // Save foo to the shared object 
trace(foo); // Should increase the value of foo with every launch of the application 

//so.clear(); // If you ever want to reset shared object call this.