Document Class Problems

Hiya folks and actionscript gurus.

I’m running into a problem trying to convert my code to a document class. I’ve read a bunch of tutorials online, and followed their instructions on it, though I keep running into “Error 1120: Access of undefined property stage.” I can’t seem to figure out what I need to do to correct this. Please help!

Here’s my code:

 
package {
 //IMPORT & INITIALIZE CLASSES
 import caurina.transitions.*;
 import caurina.transitions.properties.FilterShortcuts;
 import caurina.transitions.properties.ColorShortcuts;
 import flash.display.*;
 import flash.text.*;
 import flash.events.*;
 import flash.filters.GlowFilter;
 FilterShortcuts.init();
 ColorShortcuts.init();
 public class ExpandableGlobeClass extends MovieClip {
  //DEFINE VARIABLES
  //FILTERS
  var red_glow_in:GlowFilter = new GlowFilter(0xCC0D14,1,5,5,2,1,false,false);
  var red_glow_out:GlowFilter = new GlowFilter(0xCC0D14,0,0,0,2,1,false,false);
  var yellow_glow_in:GlowFilter = new GlowFilter(0xF6EB14,1,5,5,2,1,false,false);
  var yellow_glow_out:GlowFilter = new GlowFilter(0xF6EB14,0,0,0,2,1,false,false);
  var green_glow_in:GlowFilter = new GlowFilter(0x33CC00,1,5,5,2,1,false,false);
  var green_glow_out:GlowFilter = new GlowFilter(0x33CC00,0,0,0,2,1,false,false);
  var globe_glow:GlowFilter = new GlowFilter(0xFFFFFF,1,10,10,2,1,false,false);
  //MOVIES LOADED FROM LIBRARY
  var globe_fade_solid:MovieClip = new globe_fade_solid_mc();
  var globe_mask:MovieClip = new globe_mask_mc();
  var landmasses:MovieClip = new landmasses_sq_mc;
  var legend:MovieClip = new legend_mc();
  //PLACE DISPLAY OBJECTS & SET PROPERTIES
  stage.scaleMode = StageScaleMode.NO_SCALE;
  globe_fade_solid.x = stage.stageWidth - 210;
  globe_fade_solid.y = 10;
  globe_fade_solid.filters = [globe_glow];
  landmasses.x = globe_fade_solid.x - 198;
  landmasses.y = globe_fade_solid.y + 5;
  landmasses.width = 785;
  landmasses.height = 200;
  landmasses.mask = globe_mask;
  globe_mask.x = globe_fade_solid.x;
  globe_mask.y = globe_fade_solid.y;
  legend.x = stage.stageWidth - (stage.stageWidth - globe_fade_solid.x);
  legend.y = (globe_fade_solid.y + globe_fade_solid.height) + 20;
  legend.scaleX = 3;
  legend.scaleY = 3;
  stage.addChildAt(globe_fade_solid,0);
  stage.addChildAt(landmasses,1);
  stage.addChildAt(globe_mask,2);
  stage.addChildAt(legend,3);
  //DEFINE FUNCTIONS
  function spin_right():void {
   Tweener.addTween(landmasses, {x:globe_fade_solid.x + 198, time:10, transition:"linear", onComplete:reset_land_left});
  }
  function reset_land_left():void {
   landmasses.x = globe_fade_solid.x - 192;
   spin_right();
  }
  function red_glow(event:MouseEvent):void {
   Tweener.addTween(landmasses.red_co_double, {_filter:red_glow_in, time:1, _color:0xff0000});
   Tweener.addTween(legend.not_free_txt, {_filter:red_glow_in, time:1, _color:0xff0000});
  }
  function red_glow_stop(event:MouseEvent):void {
   Tweener.addTween(landmasses.red_co_double, {_filter:red_glow_out, time:1, _color:null});
   Tweener.addTween(legend.not_free_txt, {_filter:red_glow_out, time:1, _color:null});
  }
  function yellow_glow(event:MouseEvent):void {
   Tweener.addTween(landmasses.yellow_co_double, {_filter:yellow_glow_in, time:1, _color:0xffff00});
   Tweener.addTween(legend.part_free_txt, {_filter:yellow_glow_in, time:1, _color:0xffff00});
  }
  function yellow_glow_stop(event:MouseEvent):void {
   Tweener.addTween(landmasses.yellow_co_double, {_filter:yellow_glow_out, time:1, _color:null});
   Tweener.addTween(legend.part_free_txt, {_filter:yellow_glow_out, time:1, _color:null});
  }
  function green_glow(event:MouseEvent):void {
   Tweener.addTween(landmasses.green_co_double, {_filter:green_glow_in, time:1, _color:0x00ff00});
   Tweener.addTween(legend.free_txt, {_filter:green_glow_in, time:1, _color:0x00ff00});
  }
  function green_glow_stop(event:MouseEvent):void {
   Tweener.addTween(landmasses.green_co_double, {_filter:green_glow_out, time:1, _color:null});
   Tweener.addTween(legend.free_txt, {_filter:green_glow_out, time:1, _color:null});
  }
  //GLOBAL ACTIONS
  spin_right();
  //RED COUNTRY ACTIONS
  legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OVER, red_glow);
  legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OUT, red_glow_stop);
  //YELLOW COUNTRY ACTIONS
  legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OVER, yellow_glow);
  legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OUT, yellow_glow_stop);
  //GREEN COUNTRY ACTIONS
  legend.free_txt.addEventListener(MouseEvent.MOUSE_OVER, green_glow);
  legend.free_txt.addEventListener(MouseEvent.MOUSE_OUT, green_glow_stop);
 }
}

Thanks a bunch.

replace this


  stage.addChildAt(globe_fade_solid,0);
  stage.addChildAt(landmasses,1);
  stage.addChildAt(globe_mask,2);
  stage.addChildAt(legend,3);

with this


  addChild(globe_fade_solid);
  addChild(landmasses);
  addChild(globe_mask);
  addChild(legend);

That still didn’t do it, unfortunately. :frowning:

Here’s the error log I get:

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 49: 1120: Access of undefined property stage.
     stage.scaleMode = StageScaleMode.NO_SCALE;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 50: 1120: Access of undefined property globe_fade_solid.
     globe_fade_solid.x = stage.stageWidth - 210;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 50: 1120: Access of undefined property stage.
     globe_fade_solid.x = stage.stageWidth - 210;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 51: 1120: Access of undefined property globe_fade_solid.
     globe_fade_solid.y = 10;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 52: 1120: Access of undefined property globe_fade_solid.
     globe_fade_solid.filters = [globe_glow];

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 52: 1120: Access of undefined property globe_glow.
     globe_fade_solid.filters = [globe_glow];

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 53: 1120: Access of undefined property landmasses.
     landmasses.x = globe_fade_solid.x - 198;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 53: 1120: Access of undefined property globe_fade_solid.
     landmasses.x = globe_fade_solid.x - 198;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 54: 1120: Access of undefined property landmasses.
     landmasses.y = globe_fade_solid.y + 5;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 54: 1120: Access of undefined property globe_fade_solid.
     landmasses.y = globe_fade_solid.y + 5;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 55: 1120: Access of undefined property landmasses.
     landmasses.width = 785;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 56: 1120: Access of undefined property landmasses.
     landmasses.height = 200;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 57: 1120: Access of undefined property landmasses.
     landmasses.mask = globe_mask;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 57: 1120: Access of undefined property globe_mask.
     landmasses.mask = globe_mask;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 58: 1120: Access of undefined property globe_mask.
     globe_mask.x = globe_fade_solid.x;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 58: 1120: Access of undefined property globe_fade_solid.
     globe_mask.x = globe_fade_solid.x;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 59: 1120: Access of undefined property globe_mask.
     globe_mask.y = globe_fade_solid.y;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 59: 1120: Access of undefined property globe_fade_solid.
     globe_mask.y = globe_fade_solid.y;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 60: 1120: Access of undefined property legend.
     legend.x = stage.stageWidth - (stage.stageWidth - globe_fade_solid.x);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 60: 1120: Access of undefined property stage.
     legend.x = stage.stageWidth - (stage.stageWidth - globe_fade_solid.x);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 60: 1120: Access of undefined property stage.
     legend.x = stage.stageWidth - (stage.stageWidth - globe_fade_solid.x);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 60: 1120: Access of undefined property globe_fade_solid.
     legend.x = stage.stageWidth - (stage.stageWidth - globe_fade_solid.x);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 61: 1120: Access of undefined property legend.
     legend.y = (globe_fade_solid.y + globe_fade_solid.height) + 20;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 61: 1120: Access of undefined property globe_fade_solid.
     legend.y = (globe_fade_solid.y + globe_fade_solid.height) + 20;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 61: 1120: Access of undefined property globe_fade_solid.
     legend.y = (globe_fade_solid.y + globe_fade_solid.height) + 20;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 62: 1120: Access of undefined property legend.
     legend.scaleX = 3;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 63: 1120: Access of undefined property legend.
     legend.scaleY = 3;

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 64: 1120: Access of undefined property stage.
     stage.addChildAt(globe_fade_solid,0);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 64: 1120: Access of undefined property globe_fade_solid.
     stage.addChildAt(globe_fade_solid,0);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 65: 1120: Access of undefined property stage.
     stage.addChildAt(landmasses,1);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 65: 1120: Access of undefined property landmasses.
     stage.addChildAt(landmasses,1);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 66: 1120: Access of undefined property stage.
     stage.addChildAt(globe_mask,2);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 66: 1120: Access of undefined property globe_mask.
     stage.addChildAt(globe_mask,2);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 67: 1120: Access of undefined property stage.
     stage.addChildAt(legend,3);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 67: 1120: Access of undefined property legend.
     stage.addChildAt(legend,3);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 103: 1180: Call to a possibly undefined method spin_right.
     spin_right();

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 105: 1120: Access of undefined property legend.
     legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OVER, red_glow);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 105: 1120: Access of undefined property red_glow.
     legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OVER, red_glow);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 106: 1120: Access of undefined property legend.
     legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OUT, red_glow_stop);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 106: 1120: Access of undefined property red_glow_stop.
     legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OUT, red_glow_stop);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 109: 1120: Access of undefined property legend.
     legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OVER, yellow_glow);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 109: 1120: Access of undefined property yellow_glow.
     legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OVER, yellow_glow);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 110: 1120: Access of undefined property legend.
     legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OUT, yellow_glow_stop);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 110: 1120: Access of undefined property yellow_glow_stop.
     legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OUT, yellow_glow_stop);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 113: 1120: Access of undefined property legend.
     legend.free_txt.addEventListener(MouseEvent.MOUSE_OVER, green_glow);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 113: 1120: Access of undefined property green_glow.
     legend.free_txt.addEventListener(MouseEvent.MOUSE_OVER, green_glow);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 114: 1120: Access of undefined property legend.
     legend.free_txt.addEventListener(MouseEvent.MOUSE_OUT, green_glow_stop);

**Error** D:\Personal Projects\NadaRed\ExpandableGlobeClass.as, Line 114: 1120: Access of undefined property green_glow_stop.
     legend.free_txt.addEventListener(MouseEvent.MOUSE_OUT, green_glow_stop);

Total ActionScript Errors: 48,  Reported Errors: 48

Bump. Help!

The document class is associated with the stage, so it is unnecessary (and often incorrect) to refer to stage.whatever in the document class.
Think of the document class as extending the stage class, so the document class can directly access any of the properties of the stage.

[QUOTE=Insane au;2350246]The document class is associated with the stage, so it is unnecessary (and often incorrect) to refer to stage.whatever in the document class.
Think of the document class as extending the stage class, so the document class can directly access any of the properties of the stage.[/QUOTE]
That’s not true at all.

The problem is that you can’t be calling functions and assigning values to already defined properties in the class body. All of this must be done in a class method or constructor.

I learn best by example; would you give me an example of a class method or a constructor so I can pick it apart?

Thanks!

Document Class can inherit from Sprite or MovieClip. Stage is much different thing!
Document Class is your root and the only child of stage.

package {
 //IMPORT & INITIALIZE CLASSES
 import caurina.transitions.*;
 import caurina.transitions.properties.FilterShortcuts;
 import caurina.transitions.properties.ColorShortcuts;
 import flash.display.*;
 import flash.text.*;
 import flash.events.*;
 import flash.filters.GlowFilter;
 FilterShortcuts.init();
 ColorShortcuts.init();
 public class ExpandableGlobeClass extends MovieClip {
  //DEFINE VARIABLES
  //FILTERS
  var red_glow_in:GlowFilter = new GlowFilter(0xCC0D14,1,5,5,2,1,false,false);
  var red_glow_out:GlowFilter = new GlowFilter(0xCC0D14,0,0,0,2,1,false,false);
  var yellow_glow_in:GlowFilter = new GlowFilter(0xF6EB14,1,5,5,2,1,false,false);
  var yellow_glow_out:GlowFilter = new GlowFilter(0xF6EB14,0,0,0,2,1,false,false);
  var green_glow_in:GlowFilter = new GlowFilter(0x33CC00,1,5,5,2,1,false,false);
  var green_glow_out:GlowFilter = new GlowFilter(0x33CC00,0,0,0,2,1,false,false);
  var globe_glow:GlowFilter = new GlowFilter(0xFFFFFF,1,10,10,2,1,false,false);
  //MOVIES LOADED FROM LIBRARY
  var globe_fade_solid:MovieClip = new globe_fade_solid_mc();
  var globe_mask:MovieClip = new globe_mask_mc();
  var landmasses:MovieClip = new landmasses_sq_mc;
  var legend:MovieClip = new legend_mc();

  public function ExpandableGlobeClass() {
   globe_fade_solid.x = stage.stageWidth - 210;
   globe_fade_solid.y = 10;
   globe_fade_solid.filters = [globe_glow];
   landmasses.x = globe_fade_solid.x - 198;
   landmasses.y = globe_fade_solid.y + 5;
   landmasses.width = 785;
   landmasses.height = 200;
   landmasses.mask = globe_mask;
   globe_mask.x = globe_fade_solid.x;
   globe_mask.y = globe_fade_solid.y;
   legend.x = stage.stageWidth - (stage.stageWidth - globe_fade_solid.x);
   legend.y = (globe_fade_solid.y + globe_fade_solid.height) + 20;
   legend.scaleX = 3;
   legend.scaleY = 3;
   addChild(globe_fade_solid);
   addChild(landmasses);
   addChild(globe_mask);
   addChild(legend);
   //GLOBAL ACTIONS
   spin_right();
   //RED COUNTRY ACTIONS
   legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OVER, red_glow);
   legend.not_free_txt.addEventListener(MouseEvent.MOUSE_OUT, red_glow_stop);
   //YELLOW COUNTRY ACTIONS
   legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OVER, yellow_glow);
   legend.part_free_txt.addEventListener(MouseEvent.MOUSE_OUT, yellow_glow_stop);
   //GREEN COUNTRY ACTIONS
   legend.free_txt.addEventListener(MouseEvent.MOUSE_OVER, green_glow);
   legend.free_txt.addEventListener(MouseEvent.MOUSE_OUT, green_glow_stop);
  }
  //DEFINE FUNCTIONS
  function spin_right():void {
   Tweener.addTween(landmasses, {x:globe_fade_solid.x + 198, time:10, transition:"linear", onComplete:reset_land_left});
  }
  function reset_land_left():void {
   landmasses.x = globe_fade_solid.x - 192;
   spin_right();
  }
  function red_glow(event:MouseEvent):void {
   Tweener.addTween(landmasses.red_co_double, {_filter:red_glow_in, time:1, _color:0xff0000});
   Tweener.addTween(legend.not_free_txt, {_filter:red_glow_in, time:1, _color:0xff0000});
  }
  function red_glow_stop(event:MouseEvent):void {
   Tweener.addTween(landmasses.red_co_double, {_filter:red_glow_out, time:1, _color:null});
   Tweener.addTween(legend.not_free_txt, {_filter:red_glow_out, time:1, _color:null});
  }
  function yellow_glow(event:MouseEvent):void {
   Tweener.addTween(landmasses.yellow_co_double, {_filter:yellow_glow_in, time:1, _color:0xffff00});
   Tweener.addTween(legend.part_free_txt, {_filter:yellow_glow_in, time:1, _color:0xffff00});
  }
  function yellow_glow_stop(event:MouseEvent):void {
   Tweener.addTween(landmasses.yellow_co_double, {_filter:yellow_glow_out, time:1, _color:null});
   Tweener.addTween(legend.part_free_txt, {_filter:yellow_glow_out, time:1, _color:null});
  }
  function green_glow(event:MouseEvent):void {
   Tweener.addTween(landmasses.green_co_double, {_filter:green_glow_in, time:1, _color:0x00ff00});
   Tweener.addTween(legend.free_txt, {_filter:green_glow_in, time:1, _color:0x00ff00});
  }
  function green_glow_stop(event:MouseEvent):void {
   Tweener.addTween(landmasses.green_co_double, {_filter:green_glow_out, time:1, _color:null});
   Tweener.addTween(legend.free_txt, {_filter:green_glow_out, time:1, _color:null});
  }
 }
}

That did it, thanks very much! So it looks like I was missing the declaration of a public function to make this work.

Yeah, you basically can’t have stuff like landmasses.x = globe_fade_solid.x - 198; floating around in your class body. That sort of initialization belongs in the classes constructor.