views:

215

answers:

1

I'm using an external class to draw an object in my Flash movie but I need to get some variables from the Class as well.

I want to put the variable persPoints[0].x into a variable in my main document called newvar for example.

This is the part of the External Class I'm using

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

And somehow I will need to get that variable into my onEnterFrame funtion of my .fla below.

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() {

}

But how?!

A: 

The only change you need to make, from what I can see, is to move the persPoints array out of the set2DTo3D function to make it a member of your class instance. Like so:

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

Now that persPoints is available as an instance member, you can access it in your onEnterFrame function:

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);
}
Ross Henderson
What can I say, thanx a thousand times :)