Hej
Jeg ville have noget actionscript til at stoppe efter en scene. Så puttede jeg en if function ind og nogle true og false variabler, og nu er der slet ingen stjerner. Hvad er der galt med functionen?
keepRunning = true;
if(keepRunning = true){
this.createEmptyMovieClip("universe_mc", 10);
// star control variables
var initVel:Number = 7;
var accel:Number = 1.1;
var alphaChange:Number = 10;
var myInterval:Object = setInterval(AddStar, 10);
var maxOffset:Number = Math.sqrt(Math.pow((Stage.width/2),2) + (Math.pow((Stage.height/2),2)));
var i:Number = 0;
function AddStar() {
// a star is born
var curStar:MovieClip = universe_mc.attachMovie("star", "star_"+i, i);
++i;
// initialize the baby star
curStar._x = Math.random() * Stage.width;
curStar._y = Math.random() * Stage.height;
curStar._alpha = 0;
// calculate which angle star will fly
// the angle is based on the position of the star from
// the center of the stage.
var xOffset:Number = curStar._x - (Stage.width/2);
var yOffset:Number = curStar._y - (Stage.height/2);
var totalOffset:Number = Math.sqrt( xOffset*xOffset + yOffset*yOffset );
var velAngle:Number = Math.atan2(yOffset, xOffset);
curStar._xVel = initVel * Math.cos( velAngle );
curStar._yVel = initVel * Math.sin( velAngle );
curStar._xscale = (maxOffset - totalOffset)/7;
curStar._yscale = (maxOffset - totalOffset)/7;
// fly away little star
curStar.onEnterFrame = FlyingStar;
}
function FlyingStar () : Void {
// move the star
this._x += this._xVel;
this._y += this._yVel;
// accelerate the star
this._xVel *= accel;
this._yVel *= accel;
// fade the star in
if (this._alpha < 100) this._alpha += alphaChange;
else this._alpha = 100;
// check if the star has left the stage
// if it has, remove it so you don't hog memory
if ( (this._x < -this._width) ||
(this._x > (Stage.width + this._width)) ||
(this._y < -this._height) ||
(this._y > (Stage.height + this._height)) ) {
this.removeMovieClip();
}
}
}
(Anden linie)
Hilsen Søren