如何在Flash中创建保存按钮?

发布于 2025-01-05 02:14:12 字数 76 浏览 2 评论 0原文

我有一个游戏,我使用Flash cs5 ActionScript3。我想为游戏创建一个保存按钮。当玩家加载游戏时,保存的游戏将打开。谢谢。

I have a game and I used Flash cs5 ActionScript3. I want to create a save button for the game. When the player loads the game, the saved game will open. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习ぎ惯性依靠 2025-01-12 02:14:12

查看 SharedObject班级;特别是其数据 属性。

本质上:

  1. 像这样定义一个SharedObject

    var saveData:SharedObject = SharedObject.getLocal("MyGame");

  2. 使用 data 属性存储信息,下次打开应用程序时可以访问这些信息。请务必注意,只有当 .swf 保留在同一位置(网络上或本地)时,数据才会被保留。

    if(!saveData.data.test)
        saveData.data.test = "Test string";

  3. 您将能够访问存储在数据中的信息 预期对象:

    trace(saveData.data.test); // 测试字符串

这个想法是,最初您将创建游戏首次启动时可能想要保存的所有属性:

if(!saveData.data.ready)
{
    saveData.data.ready = true;

    saveData.data.playerHealth = 100;
    saveData.data.levelsUnlocked = 1;
}

当您点击“保存”时,覆盖这些属性:

function save(so:SharedObject):void
{
    so.data.playerHealth = player.health;
    so.data.levelsUnlocked = currentLevel;
}

Look at the SharedObject class; particularly its data property.

Essentially:

  1. Define a SharedObject like so:

    var saveData:SharedObject = SharedObject.getLocal("MyGame");

  2. Use the data property to store information which will be accessible the next time you open the application. It's important to note that the data will only be retained if the .swf remains in the same location, either on the web or locally.

    if(!saveData.data.test)
        saveData.data.test = "Test string";

  3. You'll be able to access the information you've stored in the data object as expected:

    trace(saveData.data.test); // Test string

The idea is that initially you'll create all of the properties that you may want to save when the game launches for the first time:

if(!saveData.data.ready)
{
    saveData.data.ready = true;

    saveData.data.playerHealth = 100;
    saveData.data.levelsUnlocked = 1;
}

And when you hit "save", overwrite these properties:

function save(so:SharedObject):void
{
    so.data.playerHealth = player.health;
    so.data.levelsUnlocked = currentLevel;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文