Wednesday, September 25, 2013

ActionScript 3 (AS3): list all child MovieClip


  List all child MovieClip and  make interaction between children.
For example in AS3, we want to check if  MovieClip  dragger, volume_btn and vol_slider have same parent, we can list all children of parent:
    for (var i:uint = 0; i < this.parent.numChildren; i++){
     trace ('\t|\t ' +i+'.\t name:' + this.parent.getChildAt(i).name + '\t type:' + typeof (this.parent.getChildAt(i))+ '\t' + this.parent.getChildAt(i));}

When I mouse up  for dragger, I want volume_btn in out status of button, and vol_slider invisible, we can use
      var mc:MovieClip = this.parent.getChildByName("volume_btn") as MovieClip;
     if(mc)
     {
         mc.gotoAndStop('out');
      }
       var mc1:MovieClip = this.parent.getChildByName("vol_slider") as MovieClip;
     if(mc1)
     {
         mc1.visible = false;
      }


put together:
dragger.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

function mouseUpHandler(e:MouseEvent):void{
   
           dragger.stopDrag();
     
   
      var mc:MovieClip = this.parent.getChildByName("volume_btn") as MovieClip;
     if(mc)
     {
         mc.gotoAndStop('out');
      }
       var mc1:MovieClip = this.parent.getChildByName("vol_slider") as MovieClip;
     if(mc1)
     {
         mc1.visible = false;
      }
      /*
    for (var i:uint = 0; i < this.parent.numChildren; i++){
     trace ('\t|\t ' +i+'.\t name:' + this.parent.getChildAt(i).name + '\t type:' + typeof (this.parent.getChildAt(i))+ '\t' + this.parent.getChildAt(i));
      }
    */
   
    delete this.onEnterFrame;
}   


No comments:

Post a Comment