Random Start Times for Move Clips

不问归期 提交于 2020-03-27 10:31:14

问题


I want these growing circle movie clips to start at random times within a set amount of time and then not repeat again until the whole movie loops. Does that make sense? Attached is a fla and swf to show what I want except, over course, they're not yet starting at random times.

  • animation should be a set amount of time long
  • animation should repeat but with random start times for each mc
  • all mc should play before animation loops again
  • no mc should play until 10 frames in

fla https://mega.co.nz/#!8Nwi0KzZ!QlutQQVo-KoPyNaGta9-7GLsYFthI0lMSAqTqtIIiDY

swf https://mega.co.nz/#!4cRFjZ5A!H0ndXA2DfFh79wJGua2Tgk9SquZ1rpEzZE3RCPwYfW4

Any help would be lovely!

Thanks, Rollin


回答1:


You have stop the circle movie clip at frame 1, then play it based on a Random number using the setTimeOut built in function.

you can generate a random number using this function:

function GenerateRandomNumber(max:Number, min:Number = 0):Number
{
     return Math.random() * (max - min) + min;
}

You can define the set amount of time using parameters max and min like this:

GenerateRandomNumber(4,1);

This will give you random time between 1 and 4 seconds. You can change these values as you wish.

you better define this function in the parent of the circle movieclips in order to reuse it in other places if you want.

Then, at the last frame of the circle movie clip where you stop it, you need to check if all circle movie clips are stopped or not to replay the animation. You achieve this by incrementing a counter with the total count of all finished movie clips.

You can do this using a function defined at the parent of the circle movie clips to keep track of all of them like this:

var CircleMcsPlayedCount:int = 0;
var TotalCirclesCount:int = 12;

function CircleMcFinishedPlayback()
{
     CircleMcsPlayedCount++;
     if(CircleMcsPlayedCount == TotalCirclesCount){
         CircleMcsPlayedCount = 0;
         this.gotoAndPlay(1);
     }
}

you can call it using this line of code at the last frame of the circle movie clip:

MovieClip(parent).CircleMcFinishedPlayback();

In this function, when the account equals the total number of movieclips, you set the count to zero again and move the playhead to the first frame again to play the animation again. You can put any code in this function inside the if statement that you need to be executed after all circles finishes playback.

I have modified the file you uploaded and applied all the changes in case you want to see it in action before you try it yourself.

here is the file:

https://mega.co.nz/#!JxtFgTJK!LWpuFCXTYrkmMK_6tm_1cAp3MKpB1h33URufrr1Pkk4

I have saved it as flash cs4 as I don't know your version and I have no older version.



来源:https://stackoverflow.com/questions/14945698/random-start-times-for-move-clips

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!