Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (field1.currentFrame == 1)
- {
- field1.nextFrame();
- infoText.text = "You've watered the crop. Let's wait and see how it turns out!";
- function plantStrawberry():void
- {
- field1.nextFrame();
- if (field1.currentFrame == 5)
- {
- clearInterval(strawberryInterval);
- }
- }
- var strawberryInterval = setInterval(plantStrawberry,5000);
- }
- package {
- public class Crop {
- public function Crop() {
- // constructor code
- }
- }
- }
- package {
- //imports should go here
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- //lets make this class extend MovieClip - that means it will be a MovieClip in addition to everything else you add below
- public class Crop extends MovieClip {
- //instead of setInterval, use a timer - it's easier to manage and cleanup
- //in class files, variables and functions have access modifiers, that's what the public and private words are about
- //private means only this class can ever use the var/function
- private var timer:Timer;
- public function Crop() {
- //initialize the timer - have it tick every 5 seconds, and repeat 4 times (to move you from frame 1 - 5)
- timer = new Timer(5000, 4);
- //listen for the TIMER event (which is the tick) and call the function 'grow' when the timer ticks
- timer.addEventListener(TimerEvent.TIMER, grow);
- }
- //a function that starts the timer ticking
- public function startGrowing():void {
- timer.start();
- }
- //this function is called every timer tick.
- private function grow(e:Event):void {
- this.nextFrame(); //go to the next frame of your crop
- }
- }
- }
- 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