如何将此代码从 ActionScript 2.0 转换为 ActionScript 3.0?
How to convert this code from ActionScript 2.0 to ActionScript 3.0?
我做了一个简单的评估学生的游戏,我可以构建基于ActionScript 2.0的代码。听一个炸子说ActionScript 3.0可以用在Android上。所以我希望我的游戏能在Android,
这是我的 ActionScript 2.0 代码
stop();
score=0;//skor total
step=1;//gerakan pemain
moveframe=4;
number=0;//dadu
a1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
b1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
c1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
d1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
e1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
在 AS3 中是这样的:
stop();
var score:int = 0;//skor total
var step:int = 1;//gerakan pemain
var moveframe:int = 4;
// this one is useless: number=0;//dadu
for each (var aButton:InteractiveObject in [a1,b1,c1,d1,e1])
{
aButton.addEventListener(MouseEvent.MOUSE_DOWN, onButton);
}
function onButton(e:MouseEvent):void
{
step++;
score++;
moveframe++;
root.player.x = root.getChildByName("square"+step).x;
root.player.y = root.getChildByName("square"+step).y;
root.gotoAndStop(moveframe);
root.soal.gotoAndStop(step);
trace(step);
}
请记住,如果您想让您的应用程序 运行 顺利上架 Android,您需要做的远不止这些。但是,如果您只是为了自己的乐趣而这样做,那么是的,只需迁移到 AS3 就足够了。
我做了一个简单的评估学生的游戏,我可以构建基于ActionScript 2.0的代码。听一个炸子说ActionScript 3.0可以用在Android上。所以我希望我的游戏能在Android, 这是我的 ActionScript 2.0 代码
stop();
score=0;//skor total
step=1;//gerakan pemain
moveframe=4;
number=0;//dadu
a1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
b1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
c1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
d1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
e1.onPress=function(){
number=0;
number=number+1;
score=score+1;
step=step+1;
moveframe=moveframe+1;
_root.player._x = _root["square"+step]._x;
_root.player._y = _root["square"+step]._y;
_root.gotoAndStop(moveframe);
_root.soal.gotoAndStop(step);
trace(step);
}
在 AS3 中是这样的:
stop();
var score:int = 0;//skor total
var step:int = 1;//gerakan pemain
var moveframe:int = 4;
// this one is useless: number=0;//dadu
for each (var aButton:InteractiveObject in [a1,b1,c1,d1,e1])
{
aButton.addEventListener(MouseEvent.MOUSE_DOWN, onButton);
}
function onButton(e:MouseEvent):void
{
step++;
score++;
moveframe++;
root.player.x = root.getChildByName("square"+step).x;
root.player.y = root.getChildByName("square"+step).y;
root.gotoAndStop(moveframe);
root.soal.gotoAndStop(step);
trace(step);
}
请记住,如果您想让您的应用程序 运行 顺利上架 Android,您需要做的远不止这些。但是,如果您只是为了自己的乐趣而这样做,那么是的,只需迁移到 AS3 就足够了。