movies controled by variables

  • IH8Purple
  • Guru
  • Guru
  • User avatar
  • Posts: 1215
  • Loc: Somewhere on Google Earth

Post 3+ Months Ago

I wanted to build a little health meter using

Code: [ Select ]
onClipEvent (load) {

    if (_root.life==6){
        gotoAndPlay (6)
    }
    if (_root.life==5){
        gotoAndPlay (5)
    }
    if (_root.life==4){
        gotoAndPlay (4)
    }
    if (_root.life==3){
        gotoAndPlay (3)
    }
    if (_root.life==2){
        gotoAndPlay (2)
    }
    if (_root.life==1){
        gotoAndPlay (1)
    }
    if (_root.life==0){
        gotoAndPlay (7)
    }
}
  1. onClipEvent (load) {
  2.     if (_root.life==6){
  3.         gotoAndPlay (6)
  4.     }
  5.     if (_root.life==5){
  6.         gotoAndPlay (5)
  7.     }
  8.     if (_root.life==4){
  9.         gotoAndPlay (4)
  10.     }
  11.     if (_root.life==3){
  12.         gotoAndPlay (3)
  13.     }
  14.     if (_root.life==2){
  15.         gotoAndPlay (2)
  16.     }
  17.     if (_root.life==1){
  18.         gotoAndPlay (1)
  19.     }
  20.     if (_root.life==0){
  21.         gotoAndPlay (7)
  22.     }
  23. }


the movie clip works fine when it loads, but I want to to continue to monitor the status of
Code: [ Select ]
_root.life

so I was wondering what I needed to change
Code: [ Select ]
onClipEvent (load)

to
  • IH8Purple
  • Guru
  • Guru
  • User avatar
  • Posts: 1215
  • Loc: Somewhere on Google Earth

Post 3+ Months Ago

AHH got it, needed to put in
Code: [ Select ]
onClipEvent (enterFrame)
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

If the above code works properly, it will most likely work if you reduce it to...
Code: [ Select ]
if (_root.life == 0) {
    gotoAndPlay(7);
} else {
    gotoAndPlay(life);
}
  1. if (_root.life == 0) {
  2.     gotoAndPlay(7);
  3. } else {
  4.     gotoAndPlay(life);
  5. }
as well.


Since you seem to be gotoAndPlaying the frame number of the value of life, you can reduce the if statments, by just gotoAndPlaying the value of life directly.

Since this doesn't work with life equalilng 0, you add the if/else statement. If it equals 0, then play the right frame, else play the frame life equals.


However, I don't see how gotoAndPlay is working since it will constantly be playing that frame and won't be able to play an animation.

So my only guess is that there is no animation and that you just want it to stop on that frame number.

If that is the case, change gotoAndPlay to gotoAndStop, it will save processor load.
  • IH8Purple
  • Guru
  • Guru
  • User avatar
  • Posts: 1215
  • Loc: Somewhere on Google Earth

Post 3+ Months Ago

wow, thankss alot, you are like THE flash god
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

No, i'm really not. You just don't visit the higher-up flash forums enough to see who's really out there (they put me to shame, i'll tell you that much).

But glad I could help anyway :)

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 3 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.