Skip to main content
Known Participant
September 8, 2013
Answered

class not communicating with document class

  • September 8, 2013
  • 1 reply
  • 2088 views

I created classes that would hold the layout of my level. So level 1 has an array like:

  floor1[0] = [2,1,1,1,1,1,2];
  floor1
[1] = [1,1,1,1,1,1,1];
  floor1
[2] = [1,1,1,2,1,1,1];
  floor1
[3] = [1,1,1,1,1,1,1];
  floor1
[4] = [1,1,1,2,1,1,1];
  floor1
[5] = [1,1,1,1,1,1,1];
  floor1
[6] = [2,1,1,1,1,1,2];

And level 2 would contain a different setup like:

  floor2[0] = [1,1,1,3,1,1,1];
  floor2
[1] = [1,2,1,3,1,2,1];
  floor2
[2] = [1,1,1,3,1,1,1];
  floor2
[3] = [1,1,1,2,1,1,1];
  floor2
[4] = [1,1,1,3,1,1,1];
  floor2
[5] = [1,2,1,3,1,2,1];
  floor2
[6] = [1,1,1,3,1,1,1];

Here's my problem. These classes aren't communicating with my document class. My document has a blank array called createFloor that will equal floor1 first. Once that level is finished, it will equal floor2, and so on. The code is below:

for (var Y:int=0; Y<createFloor.length; Y++)

                              {

                                        for (var X:int=0; X<createFloor.length; X++)

                                        {

                                                  var cell:MovieClip = new Tile(X,Y);

                                                  cell.gotoAndStop(createFloor);

                                                  cell.x = ((X-Y)*tileh)+365;

                                                  cell.y = ((X+Y)*tileh/2)+70;

                                                  addChild(cell);

                                                  cell.addEventListener(MouseEvent.CLICK, mouseclick);

                                                  cell.addEventListener(Event.ENTER_FRAME, onGame);

                                        }

                              }

I'm not sure how to get the document class and the level class to talk to each other. I tried making the level class extend the Main, but I fugre that had nothing to do with it. Any ideas

This topic has been closed for replies.
Correct answer kglad

Yes I do. However, this is a class that isn't being linked by a movieclip or button in my library. Maybe that's the problem?

package  {

 

          import flash.display.MovieClip;

 

          public class Level1 extends MovieClip {

 

                    public function Level1() {

 

                              public var floor1:Array = new Array();

                              floor1[0] = [2,1,1,1,1,1,2];

                              floor1[1] = [1,1,1,1,1,1,1];

                              floor1[2] = [1,1,1,2,1,1,1];

                              floor1[3] = [1,1,1,1,1,1,1];

                              floor1[4] = [1,1,1,2,1,1,1];

                              floor1[5] = [1,1,1,1,1,1,1];

                              floor1[6] = [2,1,1,1,1,1,2];

                    }

          }

 

}


change your Level1 class to:

package  {

 

          import flash.display.MovieClip;

 

          public class Level1 extends MovieClip {

public var floor1:Array;

 

                    public function Level1() {

 

                             floor1 = new Array();

                              floor1[0] = [2,1,1,1,1,1,2];

                              floor1[1] = [1,1,1,1,1,1,1];

                              floor1[2] = [1,1,1,2,1,1,1];

                              floor1[3] = [1,1,1,1,1,1,1];

                              floor1[4] = [1,1,1,2,1,1,1];

                              floor1[5] = [1,1,1,1,1,1,1];

                              floor1[6] = [2,1,1,1,1,1,2];

                    }

          }

 

}

as long as Level1 is in the same directory as your document class, in your document class you can use:

private var level1:Level1 = new Level1();

trace(level1.floor1);

1 reply

kglad
Community Expert
Community Expert
September 8, 2013

in your document class create an instance of your level class and use that instance to access its variables.

(but it actually looks like that level class should be a singleton or a static class.)

ultraruleAuthor
Known Participant
September 8, 2013

I get an error 1046: Type was not found or was not a compile-time constant: Level1

and

1180: Call to a possibly undefined method Level1.

kglad
Community Expert
Community Expert
September 8, 2013

what code is tirggering those errors?