1 Reply Latest reply on May 8, 2009 8:46 AM by kglad

    Array touble with nested MovieClips

    bigmamainthemud

      Hello,

       

           The buttons in the array are nested MC's. When I send non-nested MC's this works fine but with nested MC's for some strange reason the Controller Class doesn't see the MC i sent in in the Array but instead a child of the MC making it invisible to the indexOf method...

       

      DocumentClass.as:

      ...

           navController.addCustomButton([homeBtn_mc, danceBtn_mc, partyBtn_mc, dineBtn_mc, featBtn_mc, calBtn_mc]);

      ----------------
      NavController.as extends Controller:
      ...
      public function addCustomButton(btns:Array):void
      {
           btnsArray = btns; //Defines parent class var btnsArray
           for each(var btn:DisplayObject in btns) //receives Array
           {
                btn.addEventListener(MouseEvent.CLICK, customItem);
           }
      }
      -----------------
      Controller.as:
      ...
      public var btnsArray:Array;
      public function customItem(event:Event = null):void
      {
           model.setCurrentIndex(btnsArray.indexOf(event.target)); //with non-nested MC's this functions properly
           trace(btnsArray.indexOf(event.target)); //with Nested MC's I get -1...why?
           trace(event.target.name);// instance#
           trace(btnsArray);//[object HomeBtn_2],[object DanceBtn_4],[object PartyBtn_6]//nested MC's,[object MovieClip],[object MovieClip],[object MovieClip]//non-nested MC's
      }
      Thanks in advance for any help