2012-01-18 9 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

+0

あなたの問題に対する解決策が見つかった場合は、同じ問題を抱えている他の人たちがこれを享受できるように、ここにそれを記入してください。どうも。 – Sbhklr

答えて

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

は、動作するはずです。