# Another way to do this?

**URL:** <https://forum.kirupa.com/t/another-way-to-do-this/258031>\
**Category:** flash\
**Created:** [April 19, 2008, 9:53pm UTC](https://forum.kirupa.com/t/another-way-to-do-this/258031 "2008-04-19T21:53:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceflyin](https://avatars.discourse-cdn.com/v4/letter/i/9de053/32.png) [@iceflyin](https://forum.kirupa.com/u/iceflyin)\
**Post date:** [April 19, 2008, 9:53pm UTC](https://forum.kirupa.com/t/another-way-to-do-this/258031/1 "2008-04-19T21:53:56Z")

</div>

Is there another way to do this with less code? AS3-CS3

Each tile in my game is a MovieClip with multiple frames for different states.

```auto

//Psedocode of what I would want... A single function for generating all tile mc types.

addTile (3, 10, 10, 'wheat');

function addTile(num, cellX, cellY, type) {
    var newTile:[type] = new [type](); //Instead of having so many functions, is something like this possible?
    newTile.name = 'tile' + num;
    newTile.id = num;
    newTile.x = cellX;
    newTile.y = cellY;
    farm.addChild(newTile);
}

//My current code

//If else block that stretches for ages... *I cut out like 6 else if's.*
        if (tileType == 0) {
            addGrass(i, cellX, cellY);
        } else if (tileType == 3) {
            addPlowed(i, cellX, cellY);
        } else if (tileType == 5) {
            addWheat(i, cellX, cellY);
        }

function addGrass(num, cellX, cellY) {
    var newTile:grass = new grass();
    var stopFrame = Math.round(Math.random() * 11 +1);
    newTile.name = 'tile' + num;
    newTile.id = num;
    newTile.x = cellX;
    newTile.y = cellY;
    newTile.gotoAndStop(stopFrame);
    farm.addChild(newTile);
}
function addPlowed(num, cellX, cellY) {
    var newTile:plowed = new plowed();
    newTile.name = 'tile' + num;
    newTile.id = num;
    newTile.x = cellX;
    newTile.y = cellY;
    farm.addChild(newTile);
}
function addWheat(num, cellX, cellY) {
    var newTile:wheat = new wheat();
    newTile.name = 'tile' + num;
    newTile.id = num;
    newTile.x = cellX;
    newTile.y = cellY;
    farm.addChild(newTile);
}

```

Btw, whats the bullitin board code for actionscript [as:code]?
