jeudi 29 septembre 2016

why does the output comes undefined?-flash

I have an object name ball and ground and I'm trying to find the greatest distance between them but why does the value of "greatest" is always "undefined"?
Here's the code:

    var dt:Array = [];
    var greatest = 0;
    var i:int;
    var j:int;
    ball.addEventListener(Event.ENTER_FRAME, bg);
    function bg(event:Event)
    {
    d = Math.sqrt(ball.x-ground.x)*(ball.x * ground.x) + (ball.y - ground.y) * (ball.y - ground.y);

            for (i = 1; i < 1002; i++)
            {
                dt[i] = d;
            }
        for (j = 1; j < 1002; j++)
        {
            if(dt[j] > dt[j+1])
            {
                greatest = dt[j];
            }
            else
            {
                greatest = dt[(j+1)];
            }
        }
    }

Aucun commentaire:

Enregistrer un commentaire