Actionscript 3 在FlashDevelop中为AS3 Flash游戏编写教程;我该如何做提到source.fla的事情
学生在做AS3时,我使用FlashDevelop,我希望遵循并使用本教程帮助我创建一个塔防游戏: 我已经开始了一个新项目>ActionScript 3>ActionScript 3项目,我所拥有的只是Main.as,它包含:Actionscript 3 在FlashDevelop中为AS3 Flash游戏编写教程;我该如何做提到source.fla的事情,actionscript-3,flash,flashdevelop,Actionscript 3,Flash,Flashdevelop,学生在做AS3时,我使用FlashDevelop,我希望遵循并使用本教程帮助我创建一个塔防游戏: 我已经开始了一个新项目>ActionScript 3>ActionScript 3项目,我所拥有的只是Main.as,它包含: package { import flash.display.Sprite; import flash.events.Event; /** * ... * @author Duncan John Bunting */ public class Main exten
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author Duncan John Bunting
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
}
}
}
它提到将文件保存到source.fla文件所在的位置(我没有这个),就在第三段代码之前,它说“现在,我们必须返回到main.fla文件。创建一个新层以放置操作,并添加以下代码:”
既然我没有source.fla,如何在FlashDevelop中实现这一点?还是说在FlashDevelop中不可能
如果这是不可能的,请有人告诉我一个使用ActionScript3在FlashDevelop中创建游戏的教程的方向
谢谢。是的,在FlashDevelop中您没有访问.fla的权限,但是您仍然可以将时间线代码移植到FlashDevelop中。为此,请将函数外部的所有
var X:Y
语句置于public function Main()
行上方,无论它们出现在何处。然后,将所有函数放在init()函数声明的结尾下方。任何其他代码都应放入init()
。在您的情况下,文件应如下所示:
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author Duncan John Bunting
*/
public class Main extends Sprite
{
//setting vars to step in for turns and special blocks
var S:String = 'START';
var F:String = 'FINISH';
var U:String = 'UP';
var R:String = 'RIGHT';
var D:String = 'DOWN';
var L:String = 'LEFT';
var startDir:String;//the direction the enemies go when they enter
var finDir:String;//the direction the enemies go when they exit
var startCoord:int;//the coordinates of the beginning of the road
var lvlArray:Array = new Array();//this array will hold the formatting of the roads
//the names of these variables explain what they do
var currentLvl:int = 1;
var gameOver:Boolean = false;
var roadHolder:Sprite = new Sprite();//create an object that will hold all parts of the road
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
// stop(); MovieClip functions are not supported for Main
lvlArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,R,1,1,D,0,0,R,1,1,D,0,0,R,1,1,D,0,0,
0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,
0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,
S,D,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,R,1,F,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,
0,R,1,1,U,0,0,R,1,1,U,0,0,R,1,1,U,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
];
addChild(roadHolder);//add it to the stage
//run these functions at the start
makeRoad();
startGame();
}
function makeRoad():void{
var row:int = 0;//the current row we're working on
var block;//this will act as the block that we're placing down
for(var i:int=0;i<lvlArray.length;i++){//creating a loop that'll go through the level array
if(lvlArray[i] == 0){//if the current index is set to 0
block = new EmptyBlock();//create a gray empty block
block.graphics.beginFill(0x333333);
block.graphics.drawRect(0,0,25,25);
block.graphics.endFill();
addChild(block);
//and set the coordinates to be relative to the place in the array
block.x= (i-row*22)*25;
block.y = row*25;
} else if(lvlArray[i] == 1){//if there is supposed to be a row
//just add a box that will be a darker color and won't have any actions
block = new Shape();
block.graphics.beginFill(0x111111);
block.graphics.drawRect(0,0,25,25);
block.graphics.endFill();
block.x= (i-row*22)*25;
block.y = row*25;
roadHolder.addChild(block);//add it to the roadHolder
} else if(lvlArray[i] is String){//if it's a string, meaning a special block
//then create a special block
block = new DirectBlock(lvlArray[i],(i-row*22)*25,row*25);
addChild(block);
}
for(var c:int = 1;c<=16;c++){
if(i == c*22-1){
//if 22 columns have gone by, then we move onto the next row
row++;
}
}
}
}
function startGame():void{//we'll run this function every time a new level begins
//right now we don't have any code
}
}
}
包
{
导入flash.display.Sprite;
导入flash.events.Event;
/**
* ...
*@作者邓肯·约翰·邦廷
*/
公共类Main扩展了Sprite
{
//将VAR设置为转弯和特殊挡块的步进
var S:String='START';
变量F:String='FINISH';
变量U:String='UP';
var R:String='RIGHT';
变量D:String='DOWN';
var L:String='LEFT';
var startDir:String;//敌人进入的方向
var finDir:String;//敌人退出时的方向
var startCoord:int;//道路起点的坐标
var lvlArray:Array=new Array();//此数组将保存道路的格式
//这些变量的名称解释了它们的作用
var currentLvl:int=1;
var gameOver:Boolean=false;
var roadHolder:Sprite=new Sprite();//创建一个包含道路所有部分的对象
公共函数Main():void
{
if(stage)init();
else addEventListener(Event.ADDED_TO_STAGE,init);
}
私有函数init(e:Event=null):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
//入口点
//主屏幕不支持stop();MOVICELIP函数
lvlArray=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,R,1,1,D,0,0,R,1,1,D,0,0,R,1,1,D,0,0,
0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,
0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,
S、 D,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,R,1,F,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,
0,R,1,1,U,0,0,R,1,1,U,0,0,R,1,1,U,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
];
addChild(道路持有者);//将其添加到舞台上
//在开始时运行这些函数
makeRoad();
startGame();
}
函数makeRoad():void{
var row:int=0;//我们正在处理的当前行
var block;//这将充当我们正在放置的块
对于(变量i:int=0;i