AS3 Enemy AI (follow)

Hello there.
Im strugling for a few hours now to get this code to work in actionscript 3.
And i cant seem to succed, most probably its because im a newby and the code also might sound stupid.
The game im trying to create is a platform game.
So what i want to do is make enemy patrol between 2 points (400 and 750 you’ll see these points in my code) and if the hero player (named circle in my code) reaches a certain distance from the enemy, i want enemy to follow him (enemy speed will increase while following).
At the moment with my code the enemy speed will just increase but still patrol between those points no matter the distance.
This is the code:


package
[COLOR=#66cc66]{[/COLOR]
    [COLOR=#0066cc]import[/COLOR] flash.[COLOR=#006600]display[/COLOR].[COLOR=#006600]Sprite[/COLOR];
    [COLOR=#0066cc]import[/COLOR] flash.[COLOR=#006600]display[/COLOR].[COLOR=#0066cc]MovieClip[/COLOR];
    [COLOR=#0066cc]import[/COLOR] flash.[COLOR=#006600]display[/COLOR].[COLOR=#006600]Shape[/COLOR];
    [COLOR=#0066cc]import[/COLOR] flash.[COLOR=#006600]display[/COLOR].[COLOR=#006600]DisplayObject[/COLOR];
    [COLOR=#0066cc]import[/COLOR] flash.[COLOR=#006600]events[/COLOR].*;
 
    [COLOR=#0066cc]public[/COLOR] [COLOR=#000000]**class**[/COLOR] Enemy1 [COLOR=#0066cc]extends[/COLOR] [COLOR=#0066cc]MovieClip[/COLOR]
    [COLOR=#66cc66]{[/COLOR]
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] [COLOR=#0066cc]_root[/COLOR]:[COLOR=#0066cc]Object[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] speed:[COLOR=#0066cc]Number[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] direction:[COLOR=#0066cc]int[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] core:[COLOR=#0066cc]Object[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] yd:[COLOR=#0066cc]Number[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] xd:[COLOR=#0066cc]Number[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] gx:[COLOR=#0066cc]Number[/COLOR] = [COLOR=#cc66cc]0[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] gy:[COLOR=#0066cc]Number[/COLOR] = [COLOR=#cc66cc]0[/COLOR]; 
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] gravity:[COLOR=#0066cc]Number[/COLOR] = [COLOR=#cc66cc]1[/COLOR];
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**var**[/COLOR] [COLOR=#0066cc]target[/COLOR]:[COLOR=#0066cc]Object[/COLOR];




 
        [COLOR=#0066cc]public[/COLOR] [COLOR=#000000]**function**[/COLOR] Enemy1[COLOR=#66cc66]([/COLOR][COLOR=#66cc66])[/COLOR]
        [COLOR=#66cc66]{[/COLOR]
            addEventListener[COLOR=#66cc66]([/COLOR]Event.[COLOR=#006600]ADDED[/COLOR], beginClass[COLOR=#66cc66])[/COLOR];
            addEventListener[COLOR=#66cc66]([/COLOR]Event.[COLOR=#006600]ENTER_FRAME[/COLOR], eFrame[COLOR=#66cc66])[/COLOR];

        [COLOR=#66cc66]}[/COLOR]

        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**function**[/COLOR] beginClass[COLOR=#66cc66]([/COLOR]event:Event[COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]void[/COLOR]
        [COLOR=#66cc66]{[/COLOR]
            [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR]=[COLOR=#cc66cc]750[/COLOR];
            [COLOR=#0066cc]_root[/COLOR] = [COLOR=#0066cc]MovieClip[/COLOR][COLOR=#66cc66]([/COLOR]root[COLOR=#66cc66])[/COLOR];
            removeEventListener[COLOR=#66cc66]([/COLOR]Event.[COLOR=#006600]ADDED[/COLOR], beginClass[COLOR=#66cc66])[/COLOR];
        [COLOR=#66cc66]}[/COLOR]
 
        [COLOR=#0066cc]private[/COLOR] [COLOR=#000000]**function**[/COLOR] eFrame[COLOR=#66cc66]([/COLOR]event:Event[COLOR=#66cc66])[/COLOR]:[COLOR=#0066cc]void[/COLOR]
        [COLOR=#66cc66]{[/COLOR]
            [COLOR=#000000]**var**[/COLOR] distance = [COLOR=#0066cc]Math[/COLOR].[COLOR=#0066cc]sqrt[/COLOR][COLOR=#66cc66]([/COLOR] [COLOR=#66cc66]([/COLOR] [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR] - [COLOR=#0066cc]_root[/COLOR].[COLOR=#006600]circle[/COLOR].[COLOR=#006600]x[/COLOR] [COLOR=#66cc66])[/COLOR] * [COLOR=#66cc66]([/COLOR] [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR] - [COLOR=#0066cc]_root[/COLOR].[COLOR=#006600]circle[/COLOR].[COLOR=#006600]x[/COLOR] [COLOR=#66cc66])[/COLOR] + [COLOR=#66cc66]([/COLOR] [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]y[/COLOR] - [COLOR=#0066cc]_root[/COLOR].[COLOR=#006600]circle[/COLOR].[COLOR=#006600]y[/COLOR] [COLOR=#66cc66])[/COLOR] * [COLOR=#66cc66]([/COLOR] [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]y[/COLOR] - [COLOR=#0066cc]_root[/COLOR].[COLOR=#006600]circle[/COLOR].[COLOR=#006600]y[/COLOR] [COLOR=#66cc66])[/COLOR] [COLOR=#66cc66])[/COLOR];
            [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR] += speed * direction;
            [COLOR=#b1b100]if[/COLOR][COLOR=#66cc66]([/COLOR]distance<[COLOR=#cc66cc]300[/COLOR] && direction==-[COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR] 
            [COLOR=#66cc66]{[/COLOR]
                speed=[COLOR=#cc66cc]8[/COLOR];
                direction=-[COLOR=#cc66cc]1[/COLOR];
                [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]scaleX[/COLOR]=[COLOR=#cc66cc]-7[/COLOR]/[COLOR=#cc66cc]10[/COLOR];
                [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR]--;
            [COLOR=#66cc66]}[/COLOR]
            [COLOR=#b1b100]else[/COLOR] [COLOR=#b1b100]if[/COLOR][COLOR=#66cc66]([/COLOR]distance<[COLOR=#cc66cc]300[/COLOR] && direction==[COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR] 
            [COLOR=#66cc66]{[/COLOR]
                speed=[COLOR=#cc66cc]8[/COLOR];
                direction=[COLOR=#cc66cc]1[/COLOR];
                [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]scaleX[/COLOR]=[COLOR=#cc66cc]7[/COLOR]/[COLOR=#cc66cc]10[/COLOR];
                [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR]++;
            [COLOR=#66cc66]}[/COLOR]
            [COLOR=#b1b100]else[/COLOR]
            [COLOR=#66cc66]{[/COLOR]
                [COLOR=#b1b100]if[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR]>[COLOR=#cc66cc]750[/COLOR][COLOR=#66cc66])[/COLOR]
                [COLOR=#66cc66]{[/COLOR]
                    speed=[COLOR=#cc66cc]5[/COLOR];
                    direction=-[COLOR=#cc66cc]1[/COLOR];
                    [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]scaleX[/COLOR]=[COLOR=#cc66cc]7[/COLOR]/[COLOR=#cc66cc]10[/COLOR];
                    [COLOR=#0066cc]gotoAndStop[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];
                [COLOR=#66cc66]}[/COLOR]
                [COLOR=#b1b100]if[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR]<[COLOR=#cc66cc]400[/COLOR][COLOR=#66cc66])[/COLOR]
                [COLOR=#66cc66]{[/COLOR]
                    speed=[COLOR=#cc66cc]5[/COLOR];
                    direction=[COLOR=#cc66cc]1[/COLOR];
                    [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]scaleX[/COLOR]=-[COLOR=#cc66cc]7[/COLOR]/[COLOR=#cc66cc]10[/COLOR];
                    [COLOR=#0066cc]gotoAndStop[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#cc66cc]1[/COLOR][COLOR=#66cc66])[/COLOR];
                [COLOR=#66cc66]}[/COLOR]
            [COLOR=#66cc66]}[/COLOR]

            [COLOR=#b1b100]if[/COLOR][COLOR=#66cc66]([/COLOR]![COLOR=#0066cc]this[/COLOR].[COLOR=#006600]hitTestObject[/COLOR][COLOR=#66cc66]([/COLOR][COLOR=#0066cc]_root[/COLOR].[COLOR=#006600]platform[/COLOR][COLOR=#66cc66])[/COLOR][COLOR=#66cc66])[/COLOR]   
            [COLOR=#66cc66]{[/COLOR]
                gy += gravity; 
                [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]x[/COLOR] += gx;
                [COLOR=#0066cc]this[/COLOR].[COLOR=#006600]y[/COLOR] += gy; 
            [COLOR=#66cc66]}[/COLOR]
        [COLOR=#66cc66]}[/COLOR]
    [COLOR=#66cc66]}[/COLOR]
[COLOR=#66cc66]}[/COLOR]