Skip to main content
January 15, 2011
Answered

1120: Access of undefined property stage.

  • January 15, 2011
  • 1 reply
  • 2628 views

Hello,

I'm getting this error: 1120: Access of undefined property stage, in my document class.On the two lines where i commented.

I'm attempting to get an array from the main timeline. Pass it through a function which then adds objects to the stage depending what number is in the array.

my Document class:

package  {
     
     import flash.display.MovieClip;
     import flash.display.Stage;

     public class Levelcreator extends MovieClip{
     
          public function Levelcreator() {
               // constructor code
          }
          
          public static function getArray(levelArray:Array):void {
               for(var i:uint = 0; i < 6; i++){
                    switch (levelArray){
                         case 0:
                              var grid_mc:Grid = new Grid;
                              grid_mc.x = (40*i) + 60;
                              grid_mc.y = 60;
                              stage.addChild(grid_mc);//error here
                              break;
                         case 1:
                              var house_mc:House = new House;
                              house_mc.x = (40*i) + 60;
                              house_mc.y = 60;
                              stage.addChild(house_mc);//error here

                              break;
                    }
               }
          }

     }
     
}

then on the maintime I'm trying to pass an array to this with:

Levelcreator.getArray([0, 1, 0, 0, 1, 0]);

I cant figure out what I'm doing wrong here. Help would be much appreciated. Thank you.

This topic has been closed for replies.
Correct answer kglad

:


package  {
     
     import flash.display.MovieClip;
     import flash.display.Stage;

     public class Levelcreator extends MovieClip{
     
          public function Levelcreator() {
               // constructor code
          }
          
          public function getArray(levelArray:Array):void {
               for(var i:uint = 0; i < 6; i++){
                    switch (levelArray){
                         case 0:
                              var grid_mc:Grid = new Grid;
                              grid_mc.x = (40*i) + 60;
                              grid_mc.y = 60;
                              stage.addChild(grid_mc);//error here
                              break;
                         case 1:
                              var house_mc:House = new House;
                              house_mc.x = (40*i) + 60;
                              house_mc.y = 60;
                              stage.addChild(house_mc);//error here
                              break;
                    }
               }
          }

     }
     
}

then on the maintime

getArray([0, 1, 0, 0, 1, 0]);

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 15, 2011

:


package  {
     
     import flash.display.MovieClip;
     import flash.display.Stage;

     public class Levelcreator extends MovieClip{
     
          public function Levelcreator() {
               // constructor code
          }
          
          public function getArray(levelArray:Array):void {
               for(var i:uint = 0; i < 6; i++){
                    switch (levelArray){
                         case 0:
                              var grid_mc:Grid = new Grid;
                              grid_mc.x = (40*i) + 60;
                              grid_mc.y = 60;
                              stage.addChild(grid_mc);//error here
                              break;
                         case 1:
                              var house_mc:House = new House;
                              house_mc.x = (40*i) + 60;
                              house_mc.y = 60;
                              stage.addChild(house_mc);//error here
                              break;
                    }
               }
          }

     }
     
}

then on the maintime

getArray([0, 1, 0, 0, 1, 0]);

January 15, 2011

Thanks a lot kglad. worked like a charm.

kglad
Community Expert
Community Expert
January 15, 2011

you're welcome.