Actionscript 您只需将addEventListener代码移动到addNewClay中,但它只有一行(指的是新Clay而不是stage)。 package { import flash.display.Sprite; import flash.even

Actionscript 您只需将addEventListener代码移动到addNewClay中,但它只有一行(指的是新Clay而不是stage)。 package { import flash.display.Sprite; import flash.even,actionscript,Actionscript,您只需将addEventListener代码移动到addNewClay中,但它只有一行(指的是新Clay而不是stage)。 package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.ui.Mouse; import flash.events.TimerEvent; import fl

您只需将addEventListener代码移动到addNewClay中,但它只有一行(指的是新Clay而不是stage)。
package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.ui.Mouse;
    import flash.events.TimerEvent;
    import flash.utils.Timer;


    public class Main extends Sprite 
    {
        private var clay:Clay;
        private var clayCollection:Vector.<Clay> = new Vector.<Clay>;
        private var crash:Crash;
        private var crashCollection:Vector.<Crash> = new Vector.<Crash>;
        private var timer:Timer = new Timer(0);
        private var newClayTimer:Timer = new Timer(1000);

        public function Main()
        {
            newClayTimer.start();
            newClayTimer.addEventListener(TimerEvent.TIMER, addNewClay);

            stage.addEventListener(MouseEvent.CLICK, checkForHit);
        }

        private function checkForHit(e:MouseEvent):void
        {
            if (clayCollection.length > 0)
            {
              for (var i:int = 0; i < clayCollection.length; i++) 
              {
                if (e.target.hitTestObject(clayCollection[i]))
                {
                    clayCollection.splice(i, 1);
                    removeChild(clayCollection[i]);
                }
              }
            }
        }

        private function addNewClay(e:TimerEvent):void
        {
            clay = new Clay();
            addChild(clay);
            clayCollection.push(clay);  
        }   
    }
}
for (var i:int = 0; i < clayCollection.length; i++)  {
   var clay:Clay = clayCollection[i];
   if (e.target.hitTextObject) {
      //seems to me all clays will hit test as true with the stage?
      removeChild(clay);
      clayCollection.splice(i, 1);
   }
}
package 
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import flash.utils.Timer;


public class Main extends Sprite 
{
    private var clay:Clay;
    private var clayCollection:Vector.<Clay> = new Vector.<Clay>;
    private var crash:Crash;
    private var crashCollection:Vector.<Crash> = new Vector.<Crash>;
    private var timer:Timer = new Timer(0);
    private var newClayTimer:Timer = new Timer(1000);

    public function Main()
    {
        newClayTimer.start();
        newClayTimer.addEventListener(TimerEvent.TIMER, addNewClay);


    }

    private function checkForHit(e:MouseEvent):void
    {
        // identify the target as Clay
        var clay:Clay = e.target as Clay;
        if(contains(clay)) removeChild(clay);

        // remove it from your array
        for each (var c:Clay in clayCollection) {
             if (c == clay) clayCollection.splice(clayCollection.indexOf(c), 1);
        }


    }

    private function addNewClay(e:TimerEvent):void
    {
        clay = new Clay();
        clay.addEventListener(MouseEvent.CLICK, checkForHit);
        addChild(clay);
        clayCollection.push(clay);  
    }   
  }
}
package 
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.TimerEvent;
import flash.utils.Timer;


public class Main extends Sprite {
    private var clay:Clay;
    private var clayCollection:Vector.<Clay> = new Vector.<Clay>;
    private var timer:Timer = new Timer(0);
    private var newClayTimer:Timer = new Timer(1000);

    public function Main(){
        newClayTimer.start();
        newClayTimer.addEventListener(TimerEvent.TIMER, addNewClay);
        stage.addEventListener(MouseEvent.CLICK, checkForHit);

    }//END MAIN()

    private function checkForHit(e:MouseEvent):void{

        if (clayCollection.length > 0)
        {
          for (var i:int = 0; i != clayCollection.length; i++) 
          {
            trace(i,clayCollection.length);
            if (e.target.hitTestObject(clayCollection[i]))
            {
               removeChild(clayCollection[i]);
                clayCollection.splice(i, 1);
               i--;
            } 
          }
        }
    }//END checkForHit()

    private function addNewClay(e:TimerEvent):void{
            clay = new Clay();
            addChild(clay);
            clayCollection.push(clay);
    }//END addNewClay()

}//END MAINCLASS

}//END PACKAGE