# Timing of MainTimeline References

**URL:** <https://forum.kirupa.com/t/timing-of-maintimeline-references/297871>\
**Category:** flash\
**Created:** [October 9, 2009, 2:36pm UTC](https://forum.kirupa.com/t/timing-of-maintimeline-references/297871 "2009-10-09T14:36:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jap](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@jap](https://forum.kirupa.com/u/jap)\
**Post date:** [October 9, 2009, 2:36pm UTC](https://forum.kirupa.com/t/timing-of-maintimeline-references/297871/1 "2009-10-09T14:36:24Z")

</div>

Dear Kirupa Friend,  
_Disclaimer: I have scoured the threads in an effort to prevent redundant posts on this topic._

I’ve created a simplified version of my problem. There is an .fla with a few lines of code on the main timeline. A movieclip is on stage of the class “Box”.

The code on the main timeline is as follows:

var model:IMapModel = new MapModel();  
var testNum:Number = 7;

The code in Box.as is as follows (w/o package def):

```
public class Box extends MovieClip {
    private var _model:IMapModel; //This works fine. Not source of problem

    public function Box() {[INDENT][LEFT]addEventListener(MouseEvent.CLICK, onC);

```

[/LEFT]  
addEventListener(Event.ADDED\_TO\_STAGE, onAdded);  
this.\_model = MovieClip(this.root).model;  
trace("On constructor, model= " + this.\_model);  
trace("On constructor, root= " + MovieClip(this.root).testNum);  
trace("This should trace the model var: " + MovieClip(this.root).model);  
[/INDENT]}

```
    private function onC(e:MouseEvent):void {[INDENT] this._model = MovieClip(this.root).model;
            trace("On click, model= " + this._model);
            trace("On click, root= " + MovieClip(this.root).testNum);

```

[/INDENT]}

```
    private function onAdded(e:Event):void {[INDENT] this._model = MovieClip(this.root).model;
            trace("On added, model= " + this._model);
            trace("On added, root= " + MovieClip(this.root).testNum);

```

[/INDENT]}  
}

When I test the movie and click on the box, I get the following in the Output window (numbers added for clarity):

(1) On constructor, model= null  
(2) On constructor, root= NaN  
(3) This should trace the model var: null  
(4) On added, model= null  
(5) On added, root= NaN  
(6) On click, model= [object MapModel]  
(7) On click, root= 7

The problem I’m facing is that I want items of the Box class to hold a reference to the Model on the main timeline from the moment they are instantiated. As you can see, when I attempt this in the contructor, model traces to “null”(1). Additionally, line 3 (3) shows that a reference to the “model” var isn’t possible. I can’t seem to accomplish referencing main timeline variables and assigning them to variables within the Box class. _That is_, until I attempt to do this on a click event (6). For reasons I can’t understand, _this_ works! I would assume this has to do with not having access to the main timeline _BUT_ my movieclip is on stage and I can access it just fine with the following trace (within the Map.as constructor):

trace(MovieClip(this.root).getChildAt(0)); // Traces to “[object Box]”

Is there an intelligent/generous soul around who can/will take a moment to explain to me where I am missing the obvious? I would be ever so grateful.

Thanks in advance!

joel
