Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Actionscript 3: How to make movieclip variables work with variables on stage (Healthbar Help)
  2. var health:Number = 0;
  3.  
  4. if(health == 0)
  5. {
  6.         gotoAndStop("1")
  7. }
  8.  
  9. if(health == 1)
  10. {
  11.         gotoAndStop("2")
  12. }
  13.  
  14. if(health == 2)
  15. {
  16.         gotoAndStop("3")
  17. }
  18.        
  19. var health:Number = 0;
  20.  
  21. fortyfiveup_btn.addEventListener(MouseEvent.CLICK, fortyfiveupClick);
  22. function fortyfiveupClick(event:MouseEvent):void{
  23.     health = health+45
  24. }
  25.        
  26. //You can delete the var health:Number = 0;
  27. fortyfiveup_btn.addEventListener(MouseEvent.CLICK, fortyfiveupClick);
  28. function fortyfiveupClick(event:MouseEvent):void{
  29.     //You can write this, too: lifebar.health += 45;
  30.     lifebar.health = lifebar.health+45;
  31. }
  32.        
  33. gotoAndStop(health + 1);
  34.        
  35. //Don't let health decrease below 0
  36. if(health < 0) health = 0;
  37. //And don't above 100
  38. else if(health > 100) health = 100;
  39. gotoAndStop(health + 1);
  40.        
  41. health:int = 0;