我无法理解为什么我的数组中的项目不会沿着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 :(得分: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 {
....
然后你需要将库中的movieclip与你的类连接(对不起GUI是德语):
那应该工作。