1

I know there are quite similar questions here, but I haven't found the proper details. What would be helpful is definitely an explanation of the problems, and perhaps a base example, that anyone who searches later may be able to apply. (Not asking that you write it for me, I just find the examples helpful) I don't want to upset anyone and am kind of worried to post in a forum...

I am wondering alternatives to creating a screen based off tiles created from an array. I have been having an issue myself trying to access the movieclips that have been placed on screen, and trying to trace to find a way to reference them hasn't been working.

Anyway, take something basic like an array, and connecting it to movieclips, then how to access the movieclip itself once done. So I have been working on this, and used many different online resources, so I'm sure a lot of this is going to look familiar, just in a much messier way.

This takes the array to make the movieclips appear (Im sure at least one part in here is unnecessary, and I'm thinking I'm doing something wrong here that makes it not work out later) So this works, but feels pretty bulky.

Both are from the same main class file.

function makeWorld (anyMap, tileW, tileH) {                 
var worldWidth = anyMap[0].length;
var worldHeight = anyMap.length;
var MAP = this.addChild(new mapHolder());

    function tiler(MAP, i, j, tileW, tileH, tile) 
    {
    MAP.addChild(tile);
    tile.x = (j * tileW);
    tile.y = (i * tileH);                                               
    }                                               

for (var i = 0; i < worldWidth; ++i) {
  for (var j = 0; j < worldHeight; ++j) {
      var curTile:int = anyMap[i][j];
      if (curTile == 101) {
          var tile1 = new tileGround();
          tiler (MAP, i, j, tileW, tileH, tile1);

...

      else {
          var tile3 = new empty();
          tiler (MAP, i, j, tileW, tileH, tile3);
      }
}}}

Then there is attempting to reference it, where I'm having the issue. I don't know what to call this.MAP.tileGround by, and I have tried many things. I've read it's not such a good idea to reference by name when not very advanced so I wanted to avoid that sort of thing too.

addEventListener (Event.ENTER_FRAME, hits);
function hits (event:Event) {
    var tileCatchG:MovieClip = this.MAP.tileGround;

    if(tileCatchG.hitTestPoint(this.MAP.Char.x + leftBumpPoint.x, this.MAP.Char.y + leftBumpPoint.y, true)){
        leftBumping = true;
    } else {
        leftBumping = false;
    }

...

}

Thank you!

Kate
  • 51
  • 1
  • 5
  • You've done an okay job for a new SO poster, can you please edit this post though to include which files contain each bit of code, just prefix them with [SomeFile.as] so we can tell what is what (or if this is all just in one main class file that would be an acceptable response as well), I may ask for more code too. – shaunhusain Jun 19 '13 at 21:28
  • Yes, all one class currently. Thank you for correcting me. – Kate Jun 20 '13 at 01:04

1 Answers1

1

In looking over what you're doing a second time it would appear that you should have a reference to the 2-indexed array that represents the map.

You can create a regular (single indexed) Array at the top of the file like

public var tileArray:Array = [];

Then where you create them push them into the array

var tile1 = new tileGround();
tileArray.push(tile1);

then to reference them all you can just run a simple loop

for each(var tile:MovieClip in tileArray)
{
    //Do stuff
    if(tile instanceof tileGround)
    {
       //Do stuff specific to tileGround
    }
}
shaunhusain
  • 19,630
  • 4
  • 38
  • 51
  • Thank you very much for the response, it is very helpful, since I was looking at push before... What if I wanted to take one of those movieclips specifically? Like this is a tileGround type, do this? When I try I get errors of either referencing a static variable or it runs but tells me a term is undefined and has no properties. Sorry if I am being bothersome. – Kate Jun 20 '13 at 01:10
  • Not sure what you're referring to regarding the static variable errors. Regarding the tile ground type you can either push different tile types into different arrays (probably a good idea) or do an if in the loop to check what type they are. Read up on debugging http://www.adobe.com/devnet/flash/articles/flash_as3_debugging.html when posting problems people can only help if you can tell what line is causing the problem. If you learn to debug it will allow you to pinpoint which line an error occurs on, then you can post that. – shaunhusain Jun 20 '13 at 04:06
  • Oh, I know the error is with the `var tileCatchG:MovieClip = x;` (whatever x is supposed to be) because no matter what I try to tell it is the movie clips, I am still incorrectly giving its name, so it doesn't know what I'm trying to tell it to do. – Kate Jun 20 '13 at 04:34