我正在使用外部类在我的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() {
}
但是怎么样?
答案 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);
}