[beginner] reference object and stage

Hi all,

its me again with simple questions if you don’t mind answering.

  • i have 1 fla and 1 class file.

  • inside fla, i’ put one instance called “main” on the stage. And i put this code in frame 1:

[AS]var obj:StageHandler = new StageHandler(main);[/AS]

  • inside class file, i put this code:

[AS]package {

import flash.display.MovieClip;
import flash.display.Stage;

public class StageHandler {
    
    var _stage;
    var _main;
    
    public function StageHandler(main_obj) {
        _stage = main_obj.stage;
        _main  = main_obj;
        
        trace(_stage.stageHeight); // output: 400 
        trace(_main.height);       // output: 200
    }
}

}
[/AS]

it works perfectly. However i’m still confused with the as3 concept. in this class file, i successfully trace stage’s height and main’s height.

but, if i change the code in fla to:

[AS]var obj:StageHandler = new StageHandler(stage);[/AS]

and in class file to:
[AS]package {

import flash.display.MovieClip;
import flash.display.Stage;

public class StageHandler {
    
    var _stage;
    var _main;
    
    public function StageHandler(thisStage) {
        _stage = thisStage;
        _main  = thisStage.main;
        
        trace(_stage.stageHeight);  
        trace(_main.height); //1120: Access of undefined property main.
    }
}

}
[/AS]

i cannot trace any main’s properties. why is that? isn’t “main” inside stage?

How do i access “main” via _stage?

Thankyou all.

attached is the source.

package  {
	
	import flash.display.MovieClip;
	import flash.display.Stage;
	
	public class StageHandler {
		
		var _stage;
		var _main;
		
		public function StageHandler(thisStage) {
			_stage = thisStage;
			_main  = thisStage.getChildAt(0).main;
			
			trace(_stage.stageHeight); // output: 400 
			trace(_main.height);       // output: 200
		}
	}
}

How stage, root, and MainTimeline Fit Together - by Senocular

believe me i’ve read those article. but still i don’t get it.

can you explain why, in details?

stage is an instance of Stage class and it’s Top DisplayObject (all starts here).
Then the only child of stage is root (Document Class/Main Timeline).
Ex. stage -> root -> someContainer -> myClip