Mx.UTILS package Delegate class application

xiaoxiao2021-03-06  46

Mx.UTILS package Delegate class application

About the Delegate class, you can find in the Flash installation directory. Delegate as the name is a proxy, huh, it is not as the name, it should be translated, haha. This class is to be agency, huh, huh, how do you age? Here is an example:

1. Create a new FLA document and define a function in the script of the first frame:

Function Showheart ()

{

Trace ("I Love U, My Little Leaf");

}

2, then create an MC, create a function in this MC, and use the proxy call, this is the code:

Function showagain ()

{

Trace ("This Is Show Again Function";

Trace ("this =" this);

THIS.SHOWHEART ();

}

// Use a proxy static method

Var Fam: function = mx.utils.delegate.create (_root, showagain);

// If you have created a function pointer, then call,

Fam ();

Then you will find its output:

This is show again function

this = _level0

I love u, my little leaf

Note: Don't forget to drag the MC to the main timeline, huh, I have forgotten it, by the way

From this example, it can be seen that DELAGATE is doing, it seems to have created a function pointer, but it has changed the function of the function. But it just change the function referenced by the FAM, and the actual showagain function does not change the context. Do not believe you can call Showagain to see. In the first frame of the MC, add another call:

SHOWagain ();

Look at the output:

This is show again function

this = _level0

I love u, my little leaf

This is show again function

this = _LEVEL0.INSTANCE1

Its difference is:

The former: this = _Level0 latter this = _level0.instance1. This is not the same.

Editor: i love u, my little leaf: empty (no printing is not called)

Obviously, I want to think, the problem is very clear.

However, what is the question here is what DELEGATE did? So let's take a look, what other methods are DELEGATE:

Function Delegate: This is a constructor that is incorporated into a function.

CreateDelegate: Function: Passing an Object Returns a function.

This looks like this. You can also use the instantiated method to use delegate, the method just used is a static method!

Modify the code in the MC first frame:

Function showagain ()

{

Trace ("This Is Show Again Function";

Trace ("this =" this);

THIS.SHOWHEART ();

THIS.A_TXT.TEXT = "kkk";

// var fam: function = mx.utils.delegate.create (_root, showagain);

// fam ();

// Showagain ();

Var mydgt: mx.utils.delegate = new mx.utils.deLegate (showagain);

Var family = mydgt.createdelegate (_root);

Fam ();

Output result:

This is show again function

this = _level0

I love u, my little leaf

And there is almost no change in the first time, this should be the delegate class app, huh, more superficial, just like this. Haha. However, I can't think of it. I last post on the article on the Function class, it can be determined that both methods of the Delegate class and the Function class must have certain associations. Next discussion!

This is the source file: Click to browse this file

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

New Post(0)