as3访问控制影片剪辑每帧有相同名字的mc

var coinEffect  :MovieClip;//效果动画
   var tempMc :MovieClip;

   var coinType :int = 1;//1,2,3

    coinEffect = Reflection.createInstance("com.lz.res.CoinEffect");//获取实例
    symbolSkin.addChild(coinEffect);
    coinEffect.gotoAndStop(1);
    tempMc = coinEffect.mc;//需要控制的mc,有多帧
    tempMc.addEventListener(Event.ENTER_FRAME,onEnterFrame);//每帧判断相同名字的mc
    tempMc.gotoAndPlay(1);
    function onEnterFrame(e :Event):void
    {
     var obj :DisplayObject;
     if(tempMc.mc)
     {
      for(var i :int = 0;i<tempMc.numChildren;i++)
      {
       obj = tempMc.getChildAt(i);
       if(obj && obj.name == "mc")// 包含三帧,每帧为不同的图片
       {
        (obj as MovieClip).gotoAndStop(coinType);
       }
       i ++;
      }
     }
     if(tempMc.currentFrame == tempMc.totalFrames)
     {
      tempMc.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
      if(coinEffect && coinEffect.parent)
      {
       tempMc.gotoAndStop(1);
       coinEffect.gotoAndStop(1);
       coinEffect.parent.removeChild(coinEffect);
      }
     }
    }

  废话少说,直接上代码

  

你可能感兴趣的:(function)