0
votes

I have analized all the code of a project, in one of it's classes there's a propertie(variable) that increments within a function, it is actually an animation step, and the only ways to play a mc's next frame is with gotoAndPlay, gotoAndStop, prevFrame and nextFrame, but in the class it is just this..

public function hurt(_damage:Number):void
{
   animationStep:int;
   //trace("hurt", health, _damage)
   health-=_damage
   if(health <= 0)
   {
      kill=true
      health=0
  }
  animationStep=5 - health
  trace(animationStep);
}

so what makes flash know that animationStep is a way of animating a mv if it's only an integer var?

1
It appears that changing that variable will make the increment (step) slower as the health decreases. The only odd thing I see is that the animationStep is reset every time it runs. - durbnpoisn
the only way I know to animate a movieclip is using gotoAndPlay, ect - Michael Jose
That's fine, but set up the variable in the beginning as a global. Outside of the frame handlers. - durbnpoisn
so why the compiler knows that the variable must be passed as a parameter into the gotoAndPlay, function? - Michael Jose
No. Because that would make it local to the function. If you plan on doing that, then pass it in, and use return to send the new value. - durbnpoisn

1 Answers

0
votes

I'm setting this up as an answer because it is becoming a discussion.

It appears that changing that variable will make the increment (step) slower as the health decreases. The only odd thing I see is that the animationStep is reset every time it runs

Michael Jose: the only way I know to animate a movieclip is using gotoAndPlay, ect – Michael Jose 4 mins ago

That's fine, but set up the variable in the beginning as a global. Outside of the frame handlers.

Michael Jose: so why the compiler knows that the variable must be passed as a parameter into the gotoAndPlay, function?

No. Because that would make it local to the function. If you plan on doing that, then pass it in, and use return to send the new value.