# MovieClip referencing problem

**URL:** <https://forum.kirupa.com/t/movieclip-referencing-problem/300824>\
**Category:** flash\
**Created:** [November 28, 2009, 10:35am UTC](https://forum.kirupa.com/t/movieclip-referencing-problem/300824 "2009-11-28T10:35:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wissamboulos](https://avatars.discourse-cdn.com/v4/letter/w/e9bcb4/32.png) [@wissamboulos](https://forum.kirupa.com/u/wissamboulos)\
**Post date:** [November 28, 2009, 10:35am UTC](https://forum.kirupa.com/t/movieclip-referencing-problem/300824/1 "2009-11-28T10:35:31Z")

</div>

Hello, I am making a menu in which i want to switch ON the selected submenu and button, and OFF the previous submenu and button, could anybody please tell me what is wrong with my code:

```auto
// Attach events to menu buttons
body_mc.menu_mc.addEventListener(MouseEvent.CLICK, updateSub);

// Declaring the menu elements to update
var previousBtn:MovieClip;
var currentBtn:MovieClip;
var previousSub:MovieClip;
var currentSub:MovieClip;

// Update current and reset previous
function updateSub(event:MouseEvent):void {

    // Only if currentBtn has a value already
    if (currentBtn) {
        previousBtn=currentBtn;
        previousSub=currentSub;
        previousBtn.prevFrame();
    }
    // Update current value
    currentBtn=event.target.parent;
    currentSub=event.target.parent.parent;
    currentBtn.nextFrame();

    // Prevent animation of the same movieclip
    if (currentSub!=previousSub) {
        previousSub.gotoAndPlay("off");
        currentSub.gotoAndStop("selected");
    }

}

```

What am i missing here, i know previousBtn is not identifying currentBtn before currentBtn is gaining a value, but how is it happening anyway and ignoring the if condition?

Thanks
