# Extending MovieClip Class AS2 problems

**URL:** https://forum.kirupa.com/t/extending-movieclip-class-as2-problems/294279
**Category:** flash
**Created:** [August 11, 2009, 10:11pm UTC](https://forum.kirupa.com/t/extending-movieclip-class-as2-problems/294279 "2009-08-11T22:11:42Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![gaorellana](https://avatars.discourse-cdn.com/v4/letter/g/f9ae1b/32.png) [@gaorellana](https://forum.kirupa.com/u/gaorellana)
#### Post date: [August 11, 2009, 10:11pm UTC](https://forum.kirupa.com/t/extending-movieclip-class-as2-problems/294279/1 "2009-08-11T22:11:42Z")

</div>

I have created a class like attached at the end, I am using to create a menu that is self aware about items pressed.

Then I defined two classes that extend this one: menu1 and menu2.

class menu.menu1 extends menu.mnuPressStatus {  
function menu1(){}  
}

class menu.menu2 extends menu.mnuPressStatus {  
function menu2(){}  
}

My intention is to use the same class for two different movieclips.

What I found is that when I use it like

menu1\_mc.menuItems[0]={object1};  
menu1\_mc.menuItems[1]={object2};  
…

and then

menu2\_mc.menuItems[0]={object3};  
menu2\_mc.menuItems[1]={object4};

Then menu2\_mc.menuItems[0] takes object1 instead of object3. It is like both movieclips are linked to the same instance of “menu.mnuPressStatus”. I was expecting that having created two classes and linking them in the library to 2 different symbols I could reuse the code. Note: I did this way because both menus visuals are completly different so no way to duplicate the same symbol to get what I want

```auto

// import the Event dispatcher class (Step1)
import mx.events.EventDispatcher
class menu.mnuPressStatus extends MovieClip {
 private var _items:Array = new Array();
 private var _viewer:MovieClip;
 private var _this:MovieClip=this;
 
 //declare the dispatchEvent, addEventListener and removeEventListener methods that EventDispatcher uses (Step2)
  function dispatchEvent() {};
  function addEventListener() {};
  function removeEventListener() {}; 
 
 function mnuPressStatus() {
  init();
 }
 private function init() {
  // send instance of self to the Event Dispatcher (Step3)
  mx.events.EventDispatcher.initialize(this);
 }
 function get menuItems():Array {
  return _items;
 }
 
 function get viewer():MovieClip{
  return _viewer;
  }
 function set viewer(value:MovieClip){
  _viewer=value;
  }
 
 function setPressed(movie:MovieClip) {
  var mc:MovieClip;
  var m:Array = _items;
  var l:String="";
  for (var i:Number = 0; i<m.length; i++) {
   mc = m*.movie;
   if (mc._name == movie._name) {
    m*.pressed = true;
    m*.movie.gotoAndPlay("PRESSED");
    l=m*.link;
    }else {
    m*.pressed = false;
    m*.movie.gotoAndPlay("UP");
   }
  }
 
  //define the event object that is passed to any listeners when the event is broadcast (Step4)
  // You must specify a target property and then name of the event or the event &#8220;type&#8221; property in the event object
  //Declaro argumentos del evento
  var eventObject:Object = {target:this, type:'onItemPressed'};  
  // any optional properties
  eventObject.link = l;
 
  //dispatch the event (Step5)
  dispatchEvent(eventObject);
 }
 
 function getPressedItem():Object {
  var mc:MovieClip;
  var m:Array = _items;
  for (var i:Number = 0; i<m.length; i++) {
   if (m*.pressed) {
    return m*;
   }
  }
 }
 function isPressed(movie:MovieClip):Boolean {
  var mc:MovieClip;
  var m:Array = _items;
  for (var i:Number = 0; i<m.length; i++) {
   mc = m*.movie;
   if (movie._name==mc._name) {
    return m*.pressed;
   } 
  }
 }

```
