简体   繁体   English

如何使null MovieClip成为函数?

[英]How make null MovieClip in function?

How make null MovieClip in function? 如何使null MovieClip成为函数? I tried: 我试过了:

function one()
{
var mc:MovieClip=new MovieClip();
two(mc);
}

function two(mcref:MovieClip)
{
mcref=null;
}

but unfortunately it does not work and "mc" isn't null after function. 但不幸的是,它不起作用,并且“ mc”在函数后不为null。

It should work, try this : 它应该可以工作,试试这个:

package 
{
import flash.display.MovieClip;

public class Main extends MovieClip
{
    public var mc:MovieClip;

    public function Main():void 
    {
        mc = new MovieClip();
        trace("mc : " , mc);

        makeMovieClipNull();
        trace("mc 2: ", mc);
    }

    public function makeMovieClipNull():void
    {
        mc=null;
    }

}

}

This is scope chain issue. 这是范围链问题。 if you pass MovieClip to two() function. 如果将MovieClip传递给two()函数。 Actually passing a reference value not. 实际上没有传递参考值。 so You can't access the reference object in function. 因此,您无法在函数中访问引用对象。 valid the value or execute only within the function scope. 有效值或仅在功能范围内执行。

read a this: AS3 Funciton 阅读此: AS3 Funciton

Any time a function begins execution, a number of objects and properties are created. 每当函数开始执行时,都会创建许多对象和属性。 First, a special object called an activation object is created that stores the parameters and any local variables or functions declared in the function body. 首先,创建一个称为激活对象的特殊对象,该对象存储参数以及函数体中声明的任何局部变量或函数。 You cannot access the activation object directly, because it is an internal mechanism. 您不能直接访问激活对象,因为它是一种内部机制。 Second, a scope chain is created that contains an ordered list of objects that Flash Player or Adobe AIR checks for identifier declarations. 其次,将创建一个范围链,其中包含Flash Player或Adobe AIR检查标识符声明的对象的有序列表。 Every function that executes has a scope chain that is stored in an internal property. 每个执行的函数都有一个作用域链,该作用域链存储在内部属性中。 For a nested function, the scope chain starts with its own activation object, followed by its parent function's activation object. 对于嵌套函数,作用域链以其自己的激活对象开始,然后是其父函数的激活对象。 The chain continues in this manner until it reaches the global object. 链以这种方式继续,直到到达全局对象。 The global object is created when an ActionScript program begins, and contains all global variables and functions. 全局对象是在ActionScript程序启动时创建的,并且包含所有全局变量和函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM