在 Actionscript 3 中重新打开 Flash 时如何加载动态文本共享对象?
how to load dynamic text sharedObject when flash is reopened in Actionscript 3?
我创建了一个简单的用户名页面,在第1帧中,有一个按钮和输入文本
喜欢下面的代码
stop();
var SOlastFrame: SharedObject = SharedObject.getLocal("save_frame2");
var shared_data: String
next.addEventListener(MouseEvent.CLICK, gotomyNextFrame);
function gotomyNextFrame(e: MouseEvent): void {
shared_data = inputName.text
nextFrame()
SOlastFrame.data.lastframe = currentFrame;
SOlastFrame.flush();
}
if (SOlastFrame.data.lastframe != null) {
gotoAndStop(SOlastFrame.data.lastframe);
}
我通过添加此代码保存了最后一帧
SOlastFrame.data.lastframe = currentFrame;
SOlastFrame.flush();
为了跳转到我打开的最后一帧,我添加了这段代码
if (SOlastFrame.data.lastframe != null) {
gotoAndStop(SOlastFrame.data.lastframe);
}
在第2帧,我放了动态文本
使用这样的代码
var SOnameUser: SharedObject = SharedObject.getLocal("saveName");
SOnameUser.data.yourName = shared_data;
SOnameUser.flush();
trace(SOnameUser.data.yourName);
userName.text = "Hello " + shared_data;
if (shared_data != null) {
userName.text = shared_data;
SOnameUser.data.yourName = shared_data;
}
我觉得可以,动态文本保存成功。
如果我重新打开它,它会直接进入第2帧,因为执行结果SOlastFrame.data.lastframe。
问题是我之前保存的用户名变为空。
如何在执行 SOlastFrame.data.lastframe 时在共享对象上加载动态文本。
或
flash重新打开时如何加载sharedObject
你是这样理解的,因为当你第二次开始时,你会直接进入第 2 帧,其中 shared_data 是空的。我认为你应该重新组织...好吧,一切。
// Frame 1: Splash (you don't have it).
// First of all, use a single SO rather than two.
var SO:SharedObject = SharedObject.getLocal("my.save");
// Check if there are saved fields.
if (SO.data.userName && SO.data.lastFrame)
{
// If there are saved credentials, the user
// won't even see the Login Frame.
gotoAndStop(SO.data.lastFrame);
}
else
{
// If there are no saved credentials — proceed to the Login Frame.
nextFrame();
}
那么,这就是你的第1帧
// Frame 2: Login.
stop();
// You don't actually need to SO.flush() every time,
// it's a (feeble) measure against sudden crashes.
SO.data.lastFrame = currentFrame;
// Your code, for the most part, but simpler.
next.addEventListener(MouseEvent.CLICK, gotoNext);
function gotoNext(e:MouseEvent):void
{
// You don't need any additional variables
// to temporarily store the user name.
SO.data.userName = inputName.text;
nextFrame();
}
那么,我们开始吧。
// Frame 3: only logged (via Login Frame or via SO data)
// users reach this point.
stop();
// In case we moved from the Login Frame.
SO.data.lastFrame = currentFrame;
// The only thing left to do.
userName.text = "Hello " + SO.data.userName;
我创建了一个简单的用户名页面,在第1帧中,有一个按钮和输入文本
喜欢下面的代码
stop();
var SOlastFrame: SharedObject = SharedObject.getLocal("save_frame2");
var shared_data: String
next.addEventListener(MouseEvent.CLICK, gotomyNextFrame);
function gotomyNextFrame(e: MouseEvent): void {
shared_data = inputName.text
nextFrame()
SOlastFrame.data.lastframe = currentFrame;
SOlastFrame.flush();
}
if (SOlastFrame.data.lastframe != null) {
gotoAndStop(SOlastFrame.data.lastframe);
}
我通过添加此代码保存了最后一帧
SOlastFrame.data.lastframe = currentFrame;
SOlastFrame.flush();
为了跳转到我打开的最后一帧,我添加了这段代码
if (SOlastFrame.data.lastframe != null) {
gotoAndStop(SOlastFrame.data.lastframe);
}
在第2帧,我放了动态文本 使用这样的代码
var SOnameUser: SharedObject = SharedObject.getLocal("saveName");
SOnameUser.data.yourName = shared_data;
SOnameUser.flush();
trace(SOnameUser.data.yourName);
userName.text = "Hello " + shared_data;
if (shared_data != null) {
userName.text = shared_data;
SOnameUser.data.yourName = shared_data;
}
我觉得可以,动态文本保存成功。 如果我重新打开它,它会直接进入第2帧,因为执行结果SOlastFrame.data.lastframe。
问题是我之前保存的用户名变为空。
如何在执行 SOlastFrame.data.lastframe 时在共享对象上加载动态文本。
或
flash重新打开时如何加载sharedObject
你是这样理解的,因为当你第二次开始时,你会直接进入第 2 帧,其中 shared_data 是空的。我认为你应该重新组织...好吧,一切。
// Frame 1: Splash (you don't have it).
// First of all, use a single SO rather than two.
var SO:SharedObject = SharedObject.getLocal("my.save");
// Check if there are saved fields.
if (SO.data.userName && SO.data.lastFrame)
{
// If there are saved credentials, the user
// won't even see the Login Frame.
gotoAndStop(SO.data.lastFrame);
}
else
{
// If there are no saved credentials — proceed to the Login Frame.
nextFrame();
}
那么,这就是你的第1帧
// Frame 2: Login.
stop();
// You don't actually need to SO.flush() every time,
// it's a (feeble) measure against sudden crashes.
SO.data.lastFrame = currentFrame;
// Your code, for the most part, but simpler.
next.addEventListener(MouseEvent.CLICK, gotoNext);
function gotoNext(e:MouseEvent):void
{
// You don't need any additional variables
// to temporarily store the user name.
SO.data.userName = inputName.text;
nextFrame();
}
那么,我们开始吧。
// Frame 3: only logged (via Login Frame or via SO data)
// users reach this point.
stop();
// In case we moved from the Login Frame.
SO.data.lastFrame = currentFrame;
// The only thing left to do.
userName.text = "Hello " + SO.data.userName;