2013-06-26 156 views
2

在向.AS文件添加SharedObject時遇到困難,我試圖將用戶名添加到.flv文件中,名稱爲「username_myfile」,紅色爲5我不確定我是否將代碼保存在正確部分的類。有沒有一種將SharedObject添加到.AS文件的正確方法?將SharedObject添加到.AS文件的正確方法是什麼?

- 補充說:

import flash.net.SharedObject; 

package app 
{ 
    import flash.display.BitmapData; 
    import flash.display.Stage; 
    import flash.external.ExternalInterface; 
    **import flash.net.SharedObject;** 

    public class DataHolder 
    { 
     private static var dataHolder:DataHolder; 


     public var savedstuff:SharedObject = SharedObject.getLocal("myStuff2","/"); 

     if (savedstuff.size > 0) 
     { 
      public var username = savedstuff.data.username; 

     } 

      public var filename:String = (String(username) + "_myfile"); 

     public var rtmpPath:String = "rtmp://numbershere.compute-1.amazonaws.com/oflaDemo/"; 



     public var recorder:Recorder; 
     public var navigation:Navigation; 

     public var cameraFPS:Number = 30; 
     public var cameraWidth:Number = 640; 
     public var cameraHeight:Number = 480; 
     public var cameraQuality:Number = 88;// camera quality 

     public var timelimit:Number = 25;// limit count of seconds 

     public var stage:Stage; 

     public function DataHolder() 
     { 
      if (dataHolder) 
      { 
       throw new Error("Only one DataHolder instance should be instantiated"); 
      } 
     } 

     public static function getInstance():DataHolder 
     { 
      if (dataHolder == null) 
      { 
       dataHolder = new DataHolder(); 
      } 
      return dataHolder; 
     } 
    } 
} 
+0

@RobertHarvey謝謝! – shelfish

+0

你的代碼看起來很奇怪。 if語句直接在類定義中?甚至是什麼問題?它是否編譯? –

+0

我添加了這個,現在得到更少的錯誤** import flash.net.SharedObject; ** – shelfish

回答

1

刪除您的共享對象的申報條件,並宣佈往常一樣,即:

private var savedStuff:SharedObject; 

然後,在你的構造函數:

try { 
    savedStuff = SharedObject.getLocal("savedData"); 
} catch (error) { 
    cookiesActive = false; 
}; 

然後檢查cookiesActive ==真實的數據保存到共享對象,例如:

if (cookiesActive) { 
    savedStuff.data.levelsFinished = 1; 
} 
+0

@ moosefetcher-對不起,我不能讓你的代碼工作。 – shelfish

+0

你有沒有嘗試刪除共享對象導入周圍的'**'星星?它應該正常導入(就像任何其他必需的類一樣)。我也應該指出,你需要聲明布爾變量'cookiesActive',即; 'private var cookiesActive:Boolean'。你會得到什麼錯誤?代碼不起作用? – moosefetcher

相關問題