• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Have an Object's timer notify another object?

Engaged ,
Apr 15, 2010 Apr 15, 2010

Copy link to clipboard

Copied

I have a game where there is a main application and separate SWC with classes for the objects in the game.

I have one object interacting with a second, where the second object's class has a timer that gets started.  When the timer is up, I need the first object to move on to the next object.

For example, if the first object is a hose and the second object is a bucket, when I move the hose over the bucket I am starting a timer that increments how full the bucket is.  When the bucket is full, I need to have the host move to the next bucket.

To make life interesting, there will be a few hoses filling a few buckets, so each bucket needs to tell ITS hose to move on.

For some reason, I am getting myself quite confused about how best to accomplish this.  Suggestions?

TOPICS
ActionScript

Views

478

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2010 Apr 15, 2010

Copy link to clipboard

Copied

how does a bucket know which hose is filling it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 15, 2010 Apr 15, 2010

Copy link to clipboard

Copied

I was doing this:

var hose1:hose = new hose(); hose1.targetList = [bucket3, bucket2]; hose1.targetBucket = hose1.targetList[0]; // first bucket hose1.gotoAndPlay("filling"); actionArea.addElement(hose1); moveToBucketAndFill(hose1,hose1.targetList[0]);

and

private function moveToBucketAndFill(hose:MovieClip, bucket:MovieClip):void {      var posX:Number = bucket.x+(hose.width/2); //where to go      TweenMax.to(hose, 1, {x:posX,ease:Cubic.easeOut,onComplete:startFilling,onCompleteParams:[hose,bucket]});      }

private function startFilling(hose:MovieClip, bucket:MovieClip):void {                     var bucketFilledAmount:int;                     var bucketFillingTimer:Timer = new Timer(1000,3);                     bucketFillingTimer:Timer(TimerEvent.TIMER, function(e:Event):void {                          // and here's where I am getting stuck

                    });           }

I was going to use a timer to increment the movie clip of the bucket to one of 3 frame labels to show various degrees of looking full.  So I guess the timer could gotoAndPlay each successive label.  But then, when it reached the "full" label, that's when I need to stop the timer, moveToBucketAndFill the second bucket in the array, and startFilling with that one.  That's where I have gotten stuck.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2010 Apr 15, 2010

Copy link to clipboard

Copied

LATEST

from what you showed a bucket has no direct way to determine what's filling it.  but by looping through all hoses a bucket can see if it's a targetBucket for some hose.  so, you can do that or assign a property to a bucket to indicate what hose(es) is(are) filling it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines