我目前正在做一个实验来保存用户的每个名称(每次保存新名称时都不要替换它)。
我的问题是getLocal()
函数。我用字符串类型定义了一个变量,以使SharedObject
将数据存储到本地存储中,并定义了变量名,即它的名字每个用户。
但我收到此错误:
错误#2134:无法创建SharedObject。在 flash.net::SharedObject$/getLocal()位于类:: Main / saveNewUser() 在class :: Main / promtSave()
这是我的代码
package classes {
import flash.display.MovieClip;
import flash.net.SharedObject;
import flash.text.TextField;
import classes.user.User;
public class Main extends MovieClip {
private var _user:User;
private var _properties:Object;
private var validOrNot_txt:TextField;
private var _name_input_txt:TextField;
//define a shared object to store our user data
private var database:SharedObject;
//define an array that will hold all users
private var userList:Array;
private var nameEntered:String;
public function Main() {
userList = [];
_name_input_txt = Name_input;
validOrNot_txt = valid_or_not_TXT;
validOrNot_txt.autoSize = 'center';
//_properties={Name:String,age:int,gender:String};
// constructor code
}
public function get user():User{
return _user;
}
private function saveNewUser():void{
nameEntered=_name_input_txt.text;
_user = new User();
_user._Name = _name_input_txt.text;
database = SharedObject.getLocal(nameEntered);
userList.push(_user);
database.data.Name = _user._Name;
}
}
}
这是时间轴中的代码
import flash.events.MouseEvent;
login_btn.addEventListener(MouseEvent.CLICK, promtSave);
login_btn.buttonMode=true;
trace(Name_input.length);
function promtSave(e:MouseEvent):void{
if(Name_input.length>1){
saveNewUser();
}else{
throw(new Error('you did not enter anything'));
}
}
任何人,请帮助我:'(