0

我正在使用一个外部类在我的 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() {


}

但是怎么做?

4

1 回答 1

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);
}
于 2009-07-16T13:48:41.093 回答