很难解释这一点,我正在使用我制作的分数系统进行一个稍微复杂的游戏,我使用 []
运算符来调用该帖子中的变量名称 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
发布评论
评论(1)
但是,我认为您的情况可能会有更好的系统 - 查找设计模式。
However, I think there could be a better system for your case - look up design patterns.