Actionscript 3 初学者动作脚本/Flash-一个符号的多个实例,速度

Actionscript 3 初学者动作脚本/Flash-一个符号的多个实例,速度,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,我是一名网页设计专业的学生,在课堂上对Actionscript略作改动,我的家庭作业有一些问题。任务是使用一个符号创建10个气球,使它们以不同的速度上升到屏幕顶部,并停止仅使用AS(无时间线动画内容) 我想我差不多有了它,但我不确定为什么我不能改变每个气球的速度。他们一起站起来。有什么我做得不对的吗 import flash.display.MovieClip; import flash.events.Event; var Cball:MovieClip = new rainb

我是一名网页设计专业的学生,在课堂上对Actionscript略作改动,我的家庭作业有一些问题。任务是使用一个符号创建10个气球,使它们以不同的速度上升到屏幕顶部,并停止仅使用AS(无时间线动画内容)

我想我差不多有了它,但我不确定为什么我不能改变每个气球的速度。他们一起站起来。有什么我做得不对的吗

    import flash.display.MovieClip;
    import flash.events.Event;

var Cball:MovieClip = new rainbow();
Cball.x = 400;
Cball.y = 575;
addChild(Cball);



var Cball1:MovieClip = new rainbow();
Cball1.x = 200;
Cball1.y = 575;
addChild(Cball1);

var Cball2:MovieClip = new rainbow();
Cball2.x = 385;
Cball2.y = 575;
addChild(Cball2);

var Cball3:MovieClip = new rainbow();
Cball3.x = 500;
Cball3.y = 575;
addChild(Cball3);

var Cball4:MovieClip = new rainbow();
Cball4.x = 600;
Cball4.y = 575;
addChild(Cball4);

var Cball5:MovieClip = new rainbow();
Cball5.x = 405;
Cball5.y = 575;
addChild(Cball5);

var Cball6:MovieClip = new rainbow();
Cball6.x = 333;
Cball6.y = 575;
addChild(Cball6);

var Cball7:MovieClip = new rainbow();
Cball7.x = 250;
Cball7.y = 575;
addChild(Cball7);

var Cball8:MovieClip = new rainbow();
Cball8.x = 100;
Cball8.y = 575;
addChild(Cball8);

var Cball9:MovieClip = new rainbow();
Cball9.x = 700;
Cball9.y = 575;
addChild(Cball9);


var xVel:Number = 0;
var yVel:Number = -5;



addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);

function onLoop(evt:Event):void {


// THis is for balloon number A ********************
Cball.x += xVel;
Cball.y += yVel;
// Check for collisions on every frame
if (Cball.y >= 575) {
    yVel = -5;
}// end if
if (Cball.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number A script ******************


// THis is for balloon number 1 ********************
Cball1.x += xVel;
Cball1.y += yVel;
// Check for collisions on every frame
if (Cball1.y >= 575) {
    yVel = -5;
}// end if
if (Cball1.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 1 script ******************


    // THis is for balloon number 2 ********************
Cball2.x += xVel;
Cball2.y += yVel;
// Check for collisions on every frame
if (Cball2.y >= 550) {
    yVel = -5;
}// end if
if (Cball2.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 2 script ******************

    // THis is for balloon number 3 ********************
Cball3.x += xVel;
Cball3.y += yVel;
// Check for collisions on every frame
if (Cball3.y >= 550) {
    yVel = -5;
}// end if
if (Cball3.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 3 script ******************

    // THis is for balloon number 4 ********************
Cball4.x += xVel;
Cball4.y += yVel;
// Check for collisions on every frame
if (Cball4.y >= 550) {
    yVel = -5;
}// end if
if (Cball4.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 4 script ******************

    // THis is for balloon number 5 ********************
Cball5.x += xVel;
Cball5.y += yVel;
// Check for collisions on every frame
if (Cball5.y >= 550) {
    yVel = -5;
}// end if
if (Cball5.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 5 script ******************

    // THis is for balloon number 6 ********************
Cball6.x += xVel;
Cball6.y += yVel;
// Check for collisions on every frame
if (Cball6.y >= 550) {
    yVel = -5;
}// end if
if (Cball6.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 6 script ******************

    // THis is for balloon number 7 ********************
Cball7.x += xVel;
Cball7.y += yVel;
// Check for collisions on every frame
if (Cball7.y >= 550) {
    yVel = -5;
}// end if
if (Cball7.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 7 script ******************

    // THis is for balloon number 8 ********************
Cball8.x += xVel;
Cball8.y += yVel;
// Check for collisions on every frame
if (Cball8.y >= 550) {
    yVel = -5;
}// end if
if (Cball8.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 8 script ******************

    // THis is for balloon number 9 ********************
Cball9.x += xVel;
Cball9.y += yVel;
// Check for collisions on every frame
if (Cball9.y >= 550) {
    yVel = -5;
}// end if
if (Cball9.y <= 25) {
    yVel = 0;
} // end if
// End of balloon number 9 script ******************
} // end onloop function
导入flash.display.MovieClip;
导入flash.events.Event;
var Cball:MovieClip=新彩虹();
Cball.x=400;
Cball.y=575;
addChild(Cball);
var Cball1:MovieClip=新彩虹();
Cball1.x=200;
Cball1.y=575;
addChild(Cball1);
var Cball2:MovieClip=新彩虹();
Cball2.x=385;
Cball2.y=575;
addChild(Cball2);
var Cball3:MovieClip=新彩虹();
Cball3.x=500;
Cball3.y=575;
addChild(Cball3);
var Cball4:MovieClip=新彩虹();
Cball4.x=600;
Cball4.y=575;
addChild(Cball4);
var Cball5:MovieClip=新彩虹();
Cball5.x=405;
Cball5.y=575;
addChild(Cball5);
var Cball6:MovieClip=新彩虹();
Cball6.x=333;
Cball6.y=575;
addChild(Cball6);
var Cball7:MovieClip=新彩虹();
Cball7.x=250;
Cball7.y=575;
addChild(Cball7);
var Cball8:MovieClip=新彩虹();
Cball8.x=100;
Cball8.y=575;
addChild(Cball8);
var Cball9:MovieClip=新彩虹();
Cball9.x=700;
Cball9.y=575;
addChild(Cball9);
变量xVel:Number=0;
变量yVel:Number=-5;
addEventListener(Event.ENTER_FRAME,onLoop,false,0,true);
函数onLoop(evt:Event):void{
//这是给A号气球的********************
Cball.x+=xVel;
Cball.y+=yVel;
//检查每一帧上的碰撞
如果(Cball.y>=575){
yVel=-5;
}//如果结束
如果(Cball.y=575){
yVel=-5;
}//如果结束
如果(Cball1.y=550){
yVel=-5;
}//如果结束
如果(Cball2.y=550){
yVel=-5;
}//如果结束
如果(Cball3.y=550){
yVel=-5;
}//如果结束
如果(Cball4.y=550){
yVel=-5;
}//如果结束
如果(Cball5.y=550){
yVel=-5;
}//如果结束
如果(Cball6.y=550){
yVel=-5;
}//如果结束
如果(Cball7.y=550){
yVel=-5;
}//如果结束
如果(Cball8.y=550){
yVel=-5;
}//如果结束

如果(Cball9.y您为每个球设置了相同的yVel,那么球将以相同的速度上升

所以试着为球设置不同的yVel

var ySpeeds:Array = [-10,-9, -8, -7, -6, -5,-4,-3,-2,-1];

var save:Array = ySpeeds.concat();//save the speed

for (var i:int = 1; i <= 10; i++) {

   var ball:MovieClip = this['Cball' + i] as MovieClip;//get the target ball

   ball.x += xVel;
   ball.y += ySpeeds[i - 1];//set position

   if (ball.y >= 550) {
      ySpeeds[i - 1] = save[i - 1];//reset the speed
   } else if (ball.y <= 25) {
     ySpeeds[i - 1] = 0;
   } 
}
varyspeds:Array=[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1];
var save:Array=ySpeeds.concat();//保存速度
对于(变量i:int=1;i=550){
YSpeds[i-1]=保存[i-1];//重置速度

}否则,如果(ball.y转到您制作的气球符号,调出其动作脚本,然后将其添加到第一帧

var yVel:Number = 0.0;
下一个代码是针对您的主时间线的。 这段代码应该和你的代码完全一样,只是不需要所有的输入。我不是在运行前创建每个对象,而是动态创建它们并将它们存储在一个数组中。(有关进一步的解释,请参阅本文底部。)

我只是用这个代码

for(var index:int = 0; index < numBalloons; index++) {
    var cBall:MovieClip = new rainbow();

    cBall.x = xPosition;
    cBall.y = 400; // <- [Insert Window Height Here] - [The Radius of the Movie Clip]

    cBall.yVel = (1 + (Math.random() * (10 - 1)); // Min + Math.random() * (Max - Min)
                                                  // Gives you a velocity (1 U 10)

    balloons.push(addChild(cBall)); // Your adding a new balloon to the array and
                                    // adding it to the stage at the same time

   xPosition += 10; // <- [Insert the Diameter of One Balloon here] and maybe
                              // some buffer space

}
for(变量索引:int=0;索引var Cball1:MovieClip = new rainbow();
Cball1.x = 200;
Cball1.y = 575;
addChild(Cball1);
for(var index:int = 0; index < numBalloons; index++) {
    var cBall:MovieClip = new rainbow();

    cBall.x = xPosition;
    cBall.y = 400; // <- [Insert Window Height Here] - [The Radius of the Movie Clip]

    cBall.yVel = (1 + (Math.random() * (10 - 1)); // Min + Math.random() * (Max - Min)
                                                  // Gives you a velocity (1 U 10)

    balloons.push(addChild(cBall)); // Your adding a new balloon to the array and
                                    // adding it to the stage at the same time

   xPosition += 10; // <- [Insert the Diameter of One Balloon here] and maybe
                              // some buffer space

}