Doing a Tutorial for a AS3 Flash game in FlashDevelop; how do i do the things that mention source.fla

StackOverflow https://stackoverflow.com/questions/23162429

Вопрос

Student doing AS3, I use FlashDevelop and I am wanting to follow and use this tutorial to help me create a tower defence game: http://www.flashgametuts.com/tutorials/as3/how-to-create-a-tower-defense-game-in-as3-part-1/

I have started a new project > ActionScript 3 > ActionScript 3 Project and all I have is the Main.as which contains:

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
    }

}
}

It mentions saving files to the same place the source.fla file is (I do not have this) and just before the 3rd block of code, it says "Now, we must return back to the main .fla file. Create a new layer to place actions in, and add the following code:"

How do I do this in FlashDevelop, since I do not have a source.fla? or is it not possible in FlashDevelop?

If it is not possible, can someone please point me in the direction of a tutorial that creates a game in FlashDevelop using ActionScript3.

Thanks.

Это было полезно?

Решение

Yes, in FlashDevelop you don't have access to the .fla, but you still can port timeline code into FlashDevelop. To do this, put all var X:Y statements that are outside functions above the line public function Main(), regardless of where do they appear. Then, put all functions below the finish of init() function declaration. Any other code should be put into init(). In your case, the file should look like this:

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
}
}
}

The harder part will come when you'll be told to draw something into your .fla and assign names for it. This is still portable into FD, but instead of drawing, you'll have to code all the draw routines into FD using a class that extends Sprite if layered, or Shape if not, and use graphics property to draw simple primitives. Note that you can't directly set anchor point in FD, so your coordinates should be aligned the preset anchor point of (0,0).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top