【问题标题】:As3: Access public variable from movie clips class? (Both from timeline and within a class)As3:从影片剪辑类访问公共变量? (来自时间线和班级内)
【发布时间】:2014-03-01 20:50:27
【问题描述】:

我有一个敌人类的公共变量。

我如何在主类中访问这个变量?还是英雄班?还是什么课?

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

还有:

如何从特定影片剪辑的 TIMELINE 访问这些外部类值?

代码如下:

在 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;
}

工作动画剪辑的第 8 帧是飞行动画。在这个飞行动画中,我想在这个飞行动画的最后一帧上写这样的代码:

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

^^^^^ 我不知道如何编码。

谢谢

【问题讨论】:

    标签: actionscript-3 class variables public var


    【解决方案1】:

    我不完全确定我是否理解你的问题,你能传递一些代码吗? 小提示,您应该使用私有变量作为良好的 OOP 实践和 getter/setter 方法。在这里你可以找到如何做到这一点: http://code.tutsplus.com/tutorials/as3-101-oop-inheritance-setters-getters-basix--active-6104

    【讨论】:

      【解决方案2】:

      如果 isFlying 变量是在 WORKER.as 中定义的,并且您想要更改所有实例的变量,您应该将变量定义为 public static var isFlying = false,然后可以像 WORKER.isFlying = false 那样在没有 .as 扩展名的情况下更改它。 如果您希望每个实例更改变量 this.parent.isFlying = false 应该可以工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-19
        • 2011-08-10
        • 1970-01-01
        • 2011-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多