Skip to main content
May 8, 2014
質問

problem with flash coding

  • May 8, 2014
  • 返信数 1.
  • 408 ビュー

i have issue with this coding . i want to make the duck move horitontally but i dun know whats wrong with the code.The function for that is suppose to be moveDuck1. i would appreciate any constructive helps thanks

package  {

  import flash.display.MovieClip;

  import flash.events.TimerEvent;

  import flash.utils.Timer;

  import flash.events.MouseEvent;

  import flash.events.Event;

  public class Duck extends MovieClip {

  var moveDuck:Timer = new Timer(10);

  var timer:Timer = new Timer(100);//

  var removeTimer:Timer = new Timer(2000);//

  var speedX:Number

  public function Duck() {

  removeTimer.addEventListener(TimerEvent.TIMER,removeDuck);//

  removeTimer.start();

  this.addEventListener(MouseEvent.CLICK,killDuck);//

  //timer.addEventListener(TimerEvent.TIMER,moveDuck1);

  timer.start();//

  speedX = 10;

  }

  function killDuck(evt:MouseEvent):void

  {

  removeTimer.stop();//

  removeTimer.removeEventListener(TimerEvent.TIMER,removeDuck);//

  this.removeEventListener(MouseEvent.CLICK,killDuck);//

  moveDuck.addEventListener(TimerEvent.TIMER,duckFly);//

  moveDuck.start();//

  }

  function removeDuck(evt:TimerEvent):void

  {

  removeTimer:stop();//

  removeTimer.removeEventListener(TimerEvent.TIMER,removeDuck);//

  this.removeEventListener(MouseEvent.CLICK,killDuck);//

  this.parent.removeChild(this);//

  }

  function duckFly(evt:TimerEvent):void

  {

  this.y -= 5;//

  this.rotation += 10;//

  if (this.y < 0)//

  {

  var p:MovieClip = this.parent as MovieClip;//

  p.setScore();//

  moveDuck.stop();//

  moveDuck.removeEventListener(TimerEvent.TIMER,duckFly);//

  this.parent.removeChild(this);//

  }

  function moveDuck1(evt:TimerEvent):void

  {

  this.x += speedX;

  if (this.x <=0)

  {

  moveDuck.stop();

  moveDuck.removeEventListener(TimerEvent.TIMER,moveDuck1);

  this.parent.removeChild(this);

  }

  }

  }

}

}

このトピックへの返信は締め切られました。

返信数 1

Amy Blankenship
Legend
May 8, 2014

The place where you add the event listener that should be moving the duck is commented out.

May 8, 2014

u mean this?

i have error if i enable that

timer.addEventListener(TimerEvent.TIMER,moveDuck1);

Amy Blankenship
Legend
May 9, 2014

That would be the chap. You should be able to avoid the error if you change the function it's calling to the function you need to have called when the event happens.