# AS 2.0 OOP - reference outside MC

**URL:** https://forum.kirupa.com/t/as-2-0-oop-reference-outside-mc/279273
**Category:** flash
**Created:** [January 12, 2009, 4:30pm UTC](https://forum.kirupa.com/t/as-2-0-oop-reference-outside-mc/279273 "2009-01-12T16:30:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bigbstanley](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@bigbstanley](https://forum.kirupa.com/u/bigbstanley)
#### Post date: [January 12, 2009, 4:30pm UTC](https://forum.kirupa.com/t/as-2-0-oop-reference-outside-mc/279273/1 "2009-01-12T16:30:08Z")

</div>

I’m in the process of learning OOP and have run into a small problem. I’m trying to create a basic menu system where you can rollover and rollout of all links. When you select a link, it stays highlighted until you click another link.

I’ve given the 5 links instance names like (link0, link1, link2, link3, link4) and given them each an ID of (0,1,2,3,4) - respectively. I used to be able to do something like this:

```auto

this.onRollOver = function(){
     if(this.ID != _root.selectedLink){
          this.gotoAndPlay('in');
     }
}
this.onRollOut = function(){
     if(this.ID != _root.selectedLink){
          this.gotoAndPlay('out');
     }
}
this.onRelease = function(){
     if(this.ID != _root.selectedLink){
          _root['link'+_root.selectedLink].gotoAndPlay('out');
          _root.selectedLink = this.ID;
     }
}

```

My question for OOP though is this line: \_root[‘link’+\_root.selectedLink].gotoAndPlay(‘out’);

How can I mimik this? Should I not even put it in the OOP - should I be putting the rollovers, rollouts, and releases on the main stage that calls a function in the OOP? I’m a bit lost on this - any help would be much appreciated!

Here is my current code:

mainStage:

```auto

for (var i in a) {
        var mc = nav_com.attachMovie("mainLink", "link"+i, i);
        mc.Node = a*;
        mc.ID = i;
        mc._y = 0;
        mc._x = mc._width*i;
    }

```

OOP code:

```auto

class com.MainMenuItem extends MovieClip {
        
    private var linkLabel:MovieClip;
    private var node:XMLNode;
    private var myID:Number;
    
    public function MainMenuItem() {
        linkLabel = eval(this._target+"/linkText_mc");
    }
        
    public function set Node(n:XMLNode) {
        node = n;
        linkLabel.link_txt.text = n.attributes.label;
    }
    public function get Node():XMLNode{
        return node;
    }
    public function set ID(id:Number){
        myID = id;
    }
    public function get ID():Number {
        return myID;
    }
    

    public function onRollOver() {
        if(this.ID != _root.selectedLink){
            gotoAndPlay('in');
        }
    }
    public function onRollOut() {
        if(this.ID != _root.selectedLink){
            gotoAndPlay('out');
        }
    }
    public function onRelease() {
        if(this.ID != _root.selectedLink){
            trace(_root['link'+_root.selectedLink]);
            _root['link'+_root.selectedLink].gotoAndPlay('out');
            _root.selectedLink = this.ID;
        }
    }
    
}

```
