Intrinsic class in Flash AS2.0

xiaoxiao2021-03-06  76

Intrinsic class in Flash AS2.0

Author: senocular translation: LeeFJ

Original address: http://www.kirupa.com/developer/oop2/AS2OOPIndex.htm

In ActionScript 2.0, there is another kind of other classes, that is, the Intrinsic class, but in fact it is not a real class. It is more like some guidance related to the class, which only has a purpose, which is to provide a strict data type definition for existing classes. Macromedia uses the Intrinsic Class to define data types inside the FLASH (you can find these definitions) under the Classes folder in the Flash MX 2004 installation directory). Objects including Array, MovieClip, and Math. However, when will we use them, when do we need to define such data types?

The most likely is that when you as a developer, and is developing an ActionScript 2.0 Movie, you have to use ActionScript 1.0 in your movie, then you must define an Intrinsic class.

As we know, ActionScript 1.0 is no strict data type. This is not so bad, but it is not a good thing. In MX 2004 and its later versions, you need these data type definitions to help you maintain engineering validity and efficacy. This is why the Intrinsic class.

We assume that you have a very perfect class, which can help you complete a lot of tasks in the new project, but unfortunately, this class uses ActionScript 1.0, OK, No Problem, you can seamlessly seamlessly seamless. Combination. You don't need to use ActionScript 2.0 to rewrite your class. The only thing you have to do is writing an Instrinsic class, and the data types that have been used have been used.

[Intrinsic class is a type definition of existing classes]

All what you need to do is to create an ActionScript 2.0 class with the original class name, and tagged as Instrinsic, just like you mark the class as Dymanic (if needed, you can add them simultaneously). In this file, enter all the properties and methods of the original class correctly, but do not need to be defined. This way, you don't need to rewrite a class because you don't want to include the definition of methods and properties in the new class. Here is a such example, the code is as follows:

// You can use the following code in Wonderful.AS:

Intrinsic Class Wonderful

{

Var msg: String;

Function DOSMETHINGWONDERFUL (Allow: Boolean): void;

}

// ActionScript 1.0 Class in Main Flash Movie

Var Wonderful = Function (MSG)

{

THIS.MESSAGE = MSG;

}

Wonderful.prototype.dosomethingWonderful = function (allow)

{

IF (allow)

{

TRACE (this.Message "Is Wonderful!");

}

}

Var ITSA: Wonderful = New Wonderful ("Life");

ITSA.DOSMETHINGWONDERFUL ("YES"); // Error: Type does not match; itsa.dosomethingWonderful (true); // correct

Although this class is defined by ActionScript 1.0, the compiler still discerns the case where the data type does not match. For example, in the DOSMETHINGWONDERFUL method, it is necessary to be defined in the Wonderful.as file. The same name Instrinsic class. One thing to be clear is that if you use the Instrinsic class, you must use a VAR keyword in your original class. Otherwise, there will be an error, because the compiler will think that you actually use an existing Instrinsi, instead of being created a new class.

The establishment of MX 2004 also requires an Intrinsic class because the new generation of formation has been compiled before they use. Intrinsic class gives some information, it requires some information that has been included inside, so when you use a component in your Movie, it can check if its usage has matched. The Instrinsic class is not compiled into the SWC file, and the Instrinsic class is just some definitions, and there is no substantive code.

转载请注明原文地址:https://www.9cbs.com/read-94260.html

New Post(0)