Actionscript 3 As3:从电影剪辑类访问公共变量?(来自时间线和类内)

Actionscript 3 As3:从电影剪辑类访问公共变量?(来自时间线和类内),actionscript-3,class,variables,public,var,Actionscript 3,Class,Variables,Public,Var,我有一个敌方类的公共变量 我如何在主类中访问这个变量?还是英雄阶层?或者任何阶级 我知道您可以使用_root访问主类变量。(定义后),但如何访问外部类值 此外: 如何从特定movieclip上的时间轴访问这些外部类值 代码如下: 在Worker.as,我有 This part of code is part of a continuous ENTER_FRAME loop.. if(isFlying) { if(!faceLeft)

我有一个敌方类的公共变量

我如何在主类中访问这个变量?还是英雄阶层?或者任何阶级

我知道您可以使用_root访问主类变量。(定义后),但如何访问外部类值

此外:

如何从特定movieclip上的时间轴访问这些外部类值

代码如下:

在Worker.as,我有

This part of code is part of a continuous ENTER_FRAME loop..



        if(isFlying)
        {
            if(!faceLeft)
            {
                gotoAndStop(8);
            }
            if(faceLeft)
            {
                gotoAndStop(7);
            }

            if(flyingDestination < this.x)
            {
                if(this.x > flyingDestination)
                {
                    this.x -= 3;
                }
                else
                {
                    isFlying = false;
                    _root.mainIsFlying = false;
                }
            }
            else
            {
                if(this.x < flyingDestination)
                {
                    this.x += 3;
                }
                else
                {
                    isFlying = false;
                    _root.mainIsFlying = false;
                }
            }
        }

if(_root.isPunching)
        {
            if(this.hitTestObject(_root.ceo))
               {
                   isFlying = true;

                   if(this.x < _root.ceo.x)
                   {
                        flyToTheLeft();
                   }
                   if(this.x > _root.ceo.x)
                   {
                        flyToTheRight();
                   }

               }
        }


And these are separate functions, a.k.a not part of the ENTER_FRAME function.

private function flyToTheLeft():void
{
    flyingDestination = this.x - 100;
    faceLeft = true;
}

private function flyToTheRight():void
{
    flyingDestination = this.x + 100;
}
^^^^^ 我不知道如何编码


谢谢

我不能完全确定我是否理解您的问题,您能传递一点代码吗? 小提示,您应该使用私有变量作为良好的OOP实践和getter/setter方法。在这里,您可以找到如何做到这一点:

如果isFlying变量是在WORKER.as中定义的,并且您希望更改所有实例的变量,那么您应该将变量定义为
公共静态变量isFlying=false
,然后可以这样更改它
WORKER.isFlying=false
,而不使用.as扩展名。 如果希望每个实例更改变量,则this.parent.isFlying=false应该可以工作

stop();
WORKER.as.isFlying = false;