Guest User

Untitled

a guest
Apr 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. if (field1.currentFrame == 1)
  2. {
  3. field1.nextFrame();
  4. infoText.text = "You've watered the crop. Let's wait and see how it turns out!";
  5. function plantStrawberry():void
  6. {
  7. field1.nextFrame();
  8. if (field1.currentFrame == 5)
  9. {
  10. clearInterval(strawberryInterval);
  11. }
  12. }
  13. var strawberryInterval = setInterval(plantStrawberry,5000);
  14. }
  15.  
  16. package {
  17. public class Crop {
  18. public function Crop() {
  19. // constructor code
  20. }
  21. }
  22. }
  23.  
  24. package {
  25. //imports should go here
  26. import flash.display.MovieClip;
  27. import flash.events.Event;
  28. import flash.events.TimerEvent;
  29. import flash.utils.Timer;
  30.  
  31. //lets make this class extend MovieClip - that means it will be a MovieClip in addition to everything else you add below
  32. public class Crop extends MovieClip {
  33.  
  34. //instead of setInterval, use a timer - it's easier to manage and cleanup
  35. //in class files, variables and functions have access modifiers, that's what the public and private words are about
  36. //private means only this class can ever use the var/function
  37. private var timer:Timer;
  38.  
  39. public function Crop() {
  40. //initialize the timer - have it tick every 5 seconds, and repeat 4 times (to move you from frame 1 - 5)
  41. timer = new Timer(5000, 4);
  42. //listen for the TIMER event (which is the tick) and call the function 'grow' when the timer ticks
  43. timer.addEventListener(TimerEvent.TIMER, grow);
  44. }
  45.  
  46. //a function that starts the timer ticking
  47. public function startGrowing():void {
  48. timer.start();
  49. }
  50.  
  51. //this function is called every timer tick.
  52. private function grow(e:Event):void {
  53. this.nextFrame(); //go to the next frame of your crop
  54. }
  55. }
  56. }
  57.  
  58. field1.startGrowing(); //assuming your instance `field1` is one of the crops that you assigned the base class `Crop` to
Add Comment
Please, Sign In to add comment