Flash ActionScript 2.0 Function and Event Function Class

xiaoxiao2021-03-06  76

Flash ActionScript 2.0 Function and Event Function Class

Author: LeeFJ

What is the function is commonly referred to as a method (Method), but it is defined as a class in AS2.0. When I just started to contact flash, I just understood this, but the problem is that he is not like this, so it is a bit depressed. I'm looking over MM's information, I finally knew something about some of the more details of the function. Here is my own experience and understanding, I hope to share discussions with everyone.

First let's take a look at the function class, the Function class includes two methods and an attribute. I don't know if it is translated, it seems that function.apply () and function.call () seems to be almost, huh, huh, then look at how they use it.

Function.Apply () enables the AS code to call the function function.call () to call the function function.Prototype with a class of prototype

Function.Apply () includes two parameters: Funcobj: Specifies the THIS keyword reference in the called function, usually specified as null; argumentsObj: parameter object. Function.Apply () calls the Funcobj function, and the argumentsobj parameter list is incorporated into the called function. In the mm documentation, two methods are introduced, but I have made some modifications here, first define a modified function:

Function showText ()

{

// The print function has been called

Trace ("Function ShowText Is Applied ...");

TRACE ("this.name =" this.name);

// Output incoming parameters

For (j in arguments)

{

Trace (arguments [j]);

}

}

Then define a function that calls it:

Function Caller (FuncName, Numparameters)

{

// Get function reference

Var thefunction = evAl (FuncName);

// Number of parameters

VAR n = number (number);

/ / Generate the assumption parameters

Var parameters: array = new arch;

For (VAR i = 0; i

{

Parameters.push ("parameter" i);

}

// Create an object OBJ and add a name property

Var obj: Object = new object ();

Obj.name = "leefj";

// Specify the THIS keyword in the called function with the OBJ object

Thefunction.Apply (Obj, Parameters);

// Call the function and pass the parameters

Thefunction.Apply (Thefunction, Parameters);

}

Here you have to pass two parameters, one is a function name (String type), one is the number of parameters. Finally, call the Caller function:

// Incoming function name and number of parameters

Caller ("ShowText", 8);

Output results:

Function ShowText is Applied ...

this.name = LeefjParameter7

Parameter6

Parameter5

Parameter4

Parameter3

Parameter2

Parameter1

Parameter0

In this way, everyone has seen the result of the run, and the method of use of function.apply () will know that it can be used to call the defined function based on the user's specified name. Haha, it is like this.

Then look at the function.call () how to play. Function.call () has several parameters, the first parameter and function.Apply () effects have little difference, and the subsequent parameters will be a list of parameters as the modulated function. There is a more interesting example in the mm document, take a look:

// Define an empty function

Function myObject () {}

/ / Define the function that needs to be called

Function mymethod (obj)

{

Trace ("this == Obj?" (this == obj));

Trace ("obj.name =" obj.name);

}

// Create an object

Var obj = new myObject ();

Obj.name = "leefj";

/ / Call the MyMethod () method, and specify the THIS key in the MyMethod () method with obj,

/ / Simultaneously introduced it as a parameter

Mymethod.call (obj, obj);

The output result is:

THIS == Obj? True

Obj.name = leefj

This use function.call () is basically knew, haha, actually specifying the THIS keyword in the modulated function in the first parameter of function.Apply () and function.call (), especially Data objects such as XML, Loadvars are relatively easy to define and process data (I haven't tried it yet. Everyone can try it, I was solved with another method).

About Function.Prototype properties, the first sentence in the MM document is: if you are using actionscript 2.0, you don't need it.. Haha, so there is not much here.

But what do I want to explain? Let's take an example, huh, huh:

// Create a simple LOVE function.

Function Love (Girl, Boy)

{

TRACE (Boy "Love" Girl "!");

}

/ / Then create a new function object or function reference

VAR f: function;

// var f: function = new function ();

f = love;

F.Call (f, "leaf", "leefj");

// This is also ok ~

Var ff: function = new love ("leefj", "leef");

ff.call (); // var

Output results:

Leefj love leaf!

Leef love leefj!

'

In fact, these examples mainly illustrate the function class, its methods and properties. It must be clear that the function is a class. When you define a function, it seems to be a class, you can go to New it, you can also assign a value, this seems to be a bit messy, because in the usual OOP seems to be like This use in AS2.0 (these are not what I want to discuss here). After understanding the function class, there is a relatively helpful help for us to use functions and event processing. My test file: Click to browse this file

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

New Post(0)