[As Functional Code Tutorial 01] General Latency Code

Source: Internet
Author: User

How to use:

Write the following code to the first frame of the FLA; write delay () in any frame; the command can achieve a 3 second delay effect;

Ideas:

1. Use FPS and onenterframe to complete.

2.Flash animation default 1 seconds to play 12 frames, that is, FPS is 12.

3. Perform a onenterframe (enter frame), counter++ add 1, then how many times a second? 1 seconds to enter 12 frames, so since the addition of 12 times. So 2 seconds, 3 seconds ... So we get the formula total delay time = delay seconds * FPS principle is to use frame number to do delay.

As code:

var fps:Number = 12;
//在Flash中默认的fps值为12,如果改动了默认fps值的话这里也要相应改动;
var delaytime:Number = 3;
//延时的秒数;
var counter:Number = 0;
//计数器的初值;
function delay() {
 onEnterFrame = function () {
  if (counter < delaytime * fps) {
   this.stop();
   counter++;
  } else {
   delete this.onEnterFrame;
   counter = 0;
   this.play();
  }
 };
}

Note: When there is a onenterframe in the As Frame action, enter the code directly in the Onenterframe:

var fps:Number = 12;

var delaytime:Number = 3;
var counter:Number = 0;
if (counter < delaytime * fps) {
    counter++;
}
else {
  counter = 0;
 }

Flash Charge: FPS concept

FPS (Frames per Second): That is, the number of play frames/sec, flash defaults to 12, that is to say: The default Flash animation is 1 seconds to play 12 frames.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.