3 Replies Latest reply on Jul 16, 2010 6:09 AM by kglad

    I need to use a variable in place of instance name

    AttaBoy2 Level 4

      I have a MC with instance name sub which has a MC with instance name item9 in it.

      I'm using AS3

       

      var itemNo:String;

       

      sub.item9.addEventListener(MouseEvent.ROLL_OVER, handleRollOver9);

       

      function handleRollOver9(e:MouseEvent):void {
              itemNo = e.target.name;
              trace(itemNo);


              sub.itemNo.removeEventListener(MouseEvent.ROLL_OVER, handleRollOver9);
              sub.itemNo.gotoAndPlay("s2");
              sub.itemNo.addEventListener(MouseEvent.ROLL_OUT, handleRollOut9);
      }

       

      when I trace itemNo it returns item9 which is what I want to pass into the last 3 lines.

      in the last 3 lines if I replace itemNo with item9 it works.

       

      this is what I get in the output window:

      item9
      TypeError: Error #1010: A term is undefined and has no properties.
          at test1_fla::MainTimeline/handleRollOver9()[test1_fla.MainTimeline::frame1:25]

       

      also I tried using e.currentTarget.name that didn't help.