无法将SharedObject添加到.AS文件中,我试图将用户名添加到红色5中的.flv文件,如“username_myfile”我不确定我是否添加了将名称保存在正确名称中的代码课程的一部分。有没有一种方法将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 :(得分:1)
删除共享对象的条件声明并像往常一样声明,即:
private var savedStuff:SharedObject;
然后,在你的构造函数中:
try {
savedStuff = SharedObject.getLocal("savedData");
} catch (error) {
cookiesActive = false;
};
然后检查cookiesActive == true以将数据保存到SharedObject,例如:
if (cookiesActive) {
savedStuff.data.levelsFinished = 1;
}