从外部类获取变量

时间:2009-07-16 13:29:45

标签: flash class properties external

我正在使用外部类在我的Flash电影中绘制一个对象,但我也需要从类中获取一些变量。

我想将变量persPoints[0].x放入名为newvar的主文档中的变量中。

这是我正在使用的外部类

的一部分
class Shape {

function set2DTo3D():Void {
        var persPoints:Array = new Array();
        for (var i:Number = 0; i < this.pointsArray.length; i++) {
            persPoints[i] = new Object();
            this.perspectief = this.scaleValue / (this.scaleValue - this.pointsArray[i].z);
            persPoints[i].x = this.pointsArray[i].x * this.perspectief;
            persPoints[i].y = this.pointsArray[i].y * this.perspectief;
        }
        this.draw(persPoints);
    }
}

不知何故,我需要将该变量放入我onEnterFrame下面的.fla函数中。

var kubusMC:MovieClip = this.createEmptyMovieClip("kubusMC", 0);
kubusMC._x = Stage.width/2;//plaats de mc in het midden
kubusMC._y = Stage.height/2;

var kubus:Shape = new Shape(punten, kubusMC, 300, 1, 0x222222, 85);


this.onEnterFrame = function() {


}

但是怎么样?

1 个答案:

答案 0 :(得分:0)

根据我的看法,您需要做的唯一更改是将persPoints数组移出set2DTo3D函数,使其成为类实例的成员。像这样:

class Shape {

    var persPoints:Array = new Array();

    function set2DTo3D():Void 
    { 
        for (var i:Number = 0; i < this.pointsArray.length; i++) 
        { 
            persPoints[i] = new Object(); 
            this.perspectief = this.scaleValue / (this.scaleValue - this.pointsArray[i].z);
            persPoints[i].x = this.pointsArray[i].x * this.perspectief; 
            persPoints[i].y = this.pointsArray[i].y * this.perspectief; 
        } 

        this.draw(persPoints); 
    } 
}

现在persPoints可用作实例成员,您可以在onEnterFrame函数中访问它:

var kubusMC:MovieClip = this.createEmptyMovieClip("kubusMC", 0); kubusMC._x = Stage.width/2;//plaats de mc in het midden kubusMC._y = Stage.height/2;

var kubus:Shape = new Shape(punten, kubusMC, 300, 1, 0x222222, 85);

this.onEnterFrame = function() 
{
    var value = kubus.persPoints[0].x;

    trace("x value of kubus.persPoints[0]: " + value);
}