As 2.0 static keyword

Source: Internet
Author: User
The keyword static keyword is also more important in ActionScript 2.0. If an attribute is static, then we can call it directly ...

static (Static) keywords are also important in ActionScript 2.0. If an attribute is static, then we can call it directly without having to use the instance of the class. Most properties are manipulated by the Instance of the class, which means that they are not static.

Example:

Create a myClass Instance myinstancemyinstance = new MyClass ();//Call one of the properties trace (myinstance.property1);

If this attribute property1 is static, then we can call it directly:

Call Trace (myclass.property1) directly through the main class;

In Flash, a class with the most static attributes may be date, and all of its properties are obtained by calling the date class directly. We can do this directly: Date.getutcminutes () instead of creating a new Instance and then using this Instance to get the desired attributes. It can be said that static properties or methods are created only once in the main class without having to replicate one in each class member.

We can create static properties or methods ourselves. Here is an example:

Class Geometry {  static function getdistance (MC1, mc2) {  var distance:number = math.sqrt ((mc1._x-mc2._x) * (mc1._ x-mc2._x) + (mc1._y   -mc2._y) * (mc1._y-mc2._y));  return Distance  }}

The static function Getdistance () returns the distance between two MovieClip. We can call it in other files like this:

Distance_between_2_dots = Geometry.getdistance (dot1, Dot2);

If you remove "static" and then imagine calling Getdistance () like the method above, you will get the following error message as 2.0:

The property being referenced does is not have the static attribute



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.