2012-01-18 83 views
0

我不明白为什么我的数组中的项目不会沿着y轴向下移动,我希望它们随机出现在x轴上。这是我的代码:障碍不会移动

import flash.display.MovieClip; 
import flash.events.Event; 
import fl.transitions.Tween; 
import fl.transitions.easing.*; 

public class obstacleOne extends MovieClip { 
    private var speed:Number; 
    private var obstacleOneTypes:Array = ["obstacle1","obstacle2"]; 
    private var thisObstacleOneType:String; 

    public function obstacleOne() { 
     // constructor code 
     // pick a random number between 1 and the amount of types of litter 
     var randomNumber:uint = Math.ceil(Math.random() * obstacleOneTypes.length); 
     thisObstacleOneType = obstacleOneTypes[randomNumber - 1]; 
     this.gotoAndStop(randomNumber); 
     this.x = Math.ceil(Math.random() * 400); 
     this.y =0 - Math.random()*400; 
     speed = 4 + (Math.random()*4) 
     addEventListener(Event.ENTER_FRAME,updateMe); 
    } 

    public function caught():void{ 
     // in this function are going to animate the litter removing from the screen using a tween equation 
     // when it is finished we can remove the object 
     // now place in a random position on the beach 
     this.x = Math.ceil(Math.random() * stage.stageWidth); 
     this.y =0 - Math.random()*2000; 
    } 

    private function updateMe(evt:Event):void{ 
     this.y += speed; 
     if(y>stage.stageHeight){ 
      this.y = 7; 
      // send an event to main class to subtract score 
      //stage.dispatchEvent(new Event("hitBottom",true)); 
     }//*/ 
    } 
+0

发生了什么呢? – pkyeck 2012-01-18 21:35:28

+0

如果您发现问题的解决方案,请在此提供,以便其他具有相同问题的人员可以从中受益。谢谢。 – Sbhklr 2012-01-21 11:54:32

回答

0

它适用于我。我把这个类在一个名为“CH”,然后在主时间轴包:

import ch.obstacleOne; 

stage.addChild(new obstacleOne()); 
stage.addChild(new obstacleOne()); 
stage.addChild(new obstacleOne()); 
stage.addChild(new obstacleOne()); 

类是像以前一样:

package ch{ 

import flash.display.MovieClip; 
import flash.events.Event; 
import fl.transitions.Tween; 
import fl.transitions.easing.*; 

public class obstacleOne extends MovieClip { 
.... 

然后,你需要一个影片剪辑与磁带库连接类(对不起GUI是德国):

Screenshot

应工作即可。