# How can I fix this error?

**URL:** <https://forum.kirupa.com/t/how-can-i-fix-this-error/321516>\
**Category:** flash\
**Created:** [April 21, 2011, 4:51pm UTC](https://forum.kirupa.com/t/how-can-i-fix-this-error/321516 "2011-04-21T16:51:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinnieb](https://avatars.discourse-cdn.com/v4/letter/v/ba8739/32.png) [@vinnieb](https://forum.kirupa.com/u/vinnieb)\
**Post date:** [April 21, 2011, 4:51pm UTC](https://forum.kirupa.com/t/how-can-i-fix-this-error/321516/1 "2011-04-21T16:51:10Z")

</div>

Hi,

I am working on a piece of code and I get an error which i dont know how to fix. The piece of code below is AS2, I am trying to get it in a AS3 class. The problem is that the “dp” and the “v” variable give a duplicate error. So I tried to remove the word ‘var’ in front of it. Then ofcourse I get an error that the variable has not been declared yet. So I make a global variables at the beginning of the class. This removes the error, but the script does not work… Does anybody know how to fix this?

```auto

     function findIntersection(v1, v2)
        {
            var v3 = {};
            v3.vx = v1.p1.x - v2.p0.x;
            v3.vy = v1.p1.y - v2.p0.y;
            var dp = v3.vx * v2.dx + v3.vy * v2.dy;
            if (dp < 0)
            {
                //hits starting point
                v = v3;
            }
            else
            {
                var v4 = {};
                v4.vx = v1.p1.x - v2.p1.x;
                v4.vy = v1.p1.y - v2.p1.y;
                var dp = v4.vx*v2.dx+v4.vy*v2.dy;

                if (dp > 0)
                {
                    var v = v4;
                }
                else
                {
                    var v = projectVector(v3, v2.lx, v2.ly);
                }
            }
            return v;
        }
        

```
