使用此[]操作员调用共享对象AS3

发布于 2025-02-11 09:45:53 字数 1572 浏览 0 评论 0 原文

很难解释这一点,我正在使用我制作的分数系统进行一个稍微复杂的游戏,我使用 [] 运算符来调用该帖子中的变量名称 calling ting Instrest name name sning name

我的目标是我可以将共享对象数据更改为ShareneObject数据所需的,首先我创建一个变量data1,data2等...

var data1 = 0;
userData.data.Game1Score = data1;

var data2 = 0;
userData.data.Game1Score = data2;

// data3, data4, etc.

我创建一个变量,以便可以更改要

var data:string;

在按钮上使用的数据,我更改数据变量,

// function to the Game
function BtnGame1(event:MouseEvent):void {

    data = "data1";

}

function BtnGame2(event:MouseEvent):void {

    data = "data2";

}

以便变量数据变为:

trace(data);
// Output:
// data1
// or data2

我只想拥有1页的页面得分结果,我使用 [] 运算符更改了data1

//Button Function to Page Level
function NextoPageLevel(event:MouseEvent):void {

this[data] = 3 //example if score 3
updateScore(); // function for Update SharedObject Data

}

function updateScore():void {

userData.data.Game1Score = data1;
userData.data.Game2Score = data2;

}

data2 ,我只使用翻译器,有关更多详细信息,我有一个可以在此处下载的.fla文件

”我做的很多语法,所以我使其变得简单,但是代码不起作用

this["userData.data.Game1Score"];

,或者

var data = "userData.data.Game1Score";
this[data] = 3;

我希望像这样的流程

我的游戏流概念

it's a bit difficult to explain about this, I'm working on a slightly complicated game using score system made by me, I use the [] operator to call variable names like in this post Calling a variable given its string name

the goal is that I can change the SharedObject data as desired, first I create a variable data1, data2 etc...

var data1 = 0;
userData.data.Game1Score = data1;

var data2 = 0;
userData.data.Game1Score = data2;

// data3, data4, etc.

I create a variable so that I can change the data I want to use

var data:string;

on button i change data variable

// function to the Game
function BtnGame1(event:MouseEvent):void {

    data = "data1";

}

function BtnGame2(event:MouseEvent):void {

    data = "data2";

}

so that the variable data becomes :

trace(data);
// Output:
// data1
// or data2

i only want to have 1 page of score result, i changed data1 and data2 using [] operator

//Button Function to Page Level
function NextoPageLevel(event:MouseEvent):void {

this[data] = 3 //example if score 3
updateScore(); // function for Update SharedObject Data

}

then to update ShareObject I created a function :

function updateScore():void {

userData.data.Game1Score = data1;
userData.data.Game2Score = data2;

}

and the result is working!, SharedObject data is modified and saved, sorry if there is a mistake in English, I only use a translator, for more details I have a .fla file that can be downloaded here
SetupScore.fla

if I make a lot of level games, there will definitely be a lot of syntax that I make, so I make it simple, but the code doesn't work

this["userData.data.Game1Score"];

OR

var data = "userData.data.Game1Score";
this[data] = 3;

I want the flow like this

my game flow concept

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

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

发布评论

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

评论(1

情归归情 2025-02-18 09:45:54
this["userData"]["data"]["Game1Score"];

但是,我认为您的情况可能会有更好的系统 - 查找设计模式。

this["userData"]["data"]["Game1Score"];

However, I think there could be a better system for your case - look up design patterns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文