2

在将 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;
        }
    }
}
4

1 回答 1

1

删除共享对象的条件声明并像往常一样声明,即:

private var savedStuff:SharedObject;

然后,在您的构造函数中:

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

然后勾选 cookiesActive==true 将数据保存到 SharedObject,例如:

if (cookiesActive) {
    savedStuff.data.levelsFinished = 1;
}
于 2013-06-27T09:59:49.583 回答