Problems with targeting MovieClip

I am trying to target a MC on the stage with a turret MC, through an external AS file. I thought what I have would work to test if the target MC is in range, but apparently it won’t. Any ideas?
I want the turret to have _targeting set to true when the enemy is within 50 pixels, and then clear the _targetEnemy value and search for the next enemy in range. This is for a turret game. If I’m going about this the wrong way, whats a solution?

 ActionScript Code:
 [LEFT][COLOR=#000000]**function**[/COLOR] turretActions[COLOR=#000000]([/COLOR]event:Event[COLOR=#000000])[/COLOR]:[COLOR=#0000ff]void[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR]._placed[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
            [COLOR=#808080]*//this._targetEnemy=targetEnemy1;*[/COLOR]

            [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                [COLOR=#000000]**var**[/COLOR] myRadians:[COLOR=#0000ff]Number[/COLOR]=[COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]atan2[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR]._targetEnemy.[COLOR=#000080]x[/COLOR] - [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]x[/COLOR] + [COLOR=#000080]10[/COLOR],[COLOR=#0000ff]this[/COLOR]._targetEnemy.[COLOR=#000080]y[/COLOR] - [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]y[/COLOR] + [COLOR=#000080]10[/COLOR][COLOR=#000000])[/COLOR];
                [COLOR=#000000]**var**[/COLOR] myDegrees:[COLOR=#0000ff]Number[/COLOR]=[COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]round[/COLOR][COLOR=#000000]([/COLOR]myRadians * [COLOR=#000080]180[/COLOR] / [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]PI[/COLOR][COLOR=#000000])[/COLOR];
                [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]turret[/COLOR].[COLOR=#000080]rotation[/COLOR]=myDegrees * -[COLOR=#000080]1[/COLOR];
                [COLOR=#808080]*//this.turretbullet.rotation=myDegrees * -1;*[/COLOR]
            [COLOR=#000000]}[/COLOR]
            [COLOR=#0000ff]else[/COLOR] [COLOR=#000000]{[/COLOR]
                [COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]**var**[/COLOR] t:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]1[/COLOR]; t<[COLOR=#000080]10[/COLOR]; t++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                    [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]![COLOR=#0000ff]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                        [COLOR=#000000]**var**[/COLOR] hitEnemy = [COLOR=#0000ff]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#ff0000]"targetEnemy"[/COLOR]+t[COLOR=#000000]][/COLOR];
                        [COLOR=#000000]**var**[/COLOR] hitEnemyDistX = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]abs[/COLOR][COLOR=#000000]([/COLOR]hitEnemy.[COLOR=#000080]x[/COLOR]-[COLOR=#0000ff]this[/COLOR].[COLOR=#000080]x[/COLOR][COLOR=#000000])[/COLOR];
                        [COLOR=#000000]**var**[/COLOR] hitEnemyDistY = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]abs[/COLOR][COLOR=#000000]([/COLOR]hitEnemy.[COLOR=#000080]y[/COLOR]-[COLOR=#0000ff]this[/COLOR].[COLOR=#000080]y[/COLOR][COLOR=#000000])[/COLOR];
                        [COLOR=#000000]**var**[/COLOR] hitEnemyDist:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]sqrt[/COLOR][COLOR=#000000]([/COLOR]hitEnemyDistX*hitEnemyDistX + hitEnemyDistY*hitEnemyDistY[COLOR=#000000])[/COLOR];
                        [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]hitEnemyDist<[COLOR=#000080]50[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                            [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]![COLOR=#0000ff]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                                [COLOR=#0000ff]this[/COLOR]._targetEnemy = hitEnemy;
                                [COLOR=#0000ff]this[/COLOR]._targeting = [COLOR=#000000]**true**[/COLOR];x
                            [COLOR=#000000]}[/COLOR]
                        [COLOR=#000000]}[/COLOR]
                    [COLOR=#000000]}[/COLOR]
                    [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                        [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]hitEnemyDist>[COLOR=#000080]50[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                            [COLOR=#0000ff]this[/COLOR]._targeting = [COLOR=#000000]**false**[/COLOR];
                        [COLOR=#000000]}[/COLOR]
                    [COLOR=#000000]}[/COLOR]
                [COLOR=#000000]}[/COLOR]
            [COLOR=#000000]}[/COLOR]
        [COLOR=#000000]}[/COLOR]
    [COLOR=#000000]}[/COLOR]

[/LEFT]

Any ideas? Is what I’m trying to do not clear?

A few more details would help. What exactly is not working?

The problem that Im having is Error #1010: A term is undefined and has no properties.
What I am trying to do is target the first target to enter within a distance of 50 pixels, then have it switch to the next target within that range when the original target is greater than 50 pixels away.
When there is a target in range, the turret should rotate towards target. This is done by setting the _targeting to true and passing the target value to the the _targetEnemy variable. Currently, it won’t rotate to the target. Maybe there’s a better way than what I’m doing? Or maybe I’m just missing something?

This is my current code:

ActionScript Code:
[LEFT][COLOR=#000000]**function**[/COLOR] turretActions[COLOR=#000000]([/COLOR]event:Event[COLOR=#000000])[/COLOR]:[COLOR=#0000FF]void[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR]._placed[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
            [COLOR=#808080]*//this._targetEnemy=targetEnemy1;*[/COLOR]

            [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                [COLOR=#000000]**var**[/COLOR] myRadians:[COLOR=#0000FF]Number[/COLOR]=[COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]atan2[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR]._targetEnemy.[COLOR=#000080]x[/COLOR] - [COLOR=#0000FF]this[/COLOR].[COLOR=#000080]x[/COLOR] + [COLOR=#000080]10[/COLOR],[COLOR=#0000FF]this[/COLOR]._targetEnemy.[COLOR=#000080]y[/COLOR] - [COLOR=#0000FF]this[/COLOR].[COLOR=#000080]y[/COLOR] + [COLOR=#000080]10[/COLOR][COLOR=#000000])[/COLOR];
                [COLOR=#000000]**var**[/COLOR] myDegrees:[COLOR=#0000FF]Number[/COLOR]=[COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]round[/COLOR][COLOR=#000000]([/COLOR]myRadians * [COLOR=#000080]180[/COLOR] / [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]PI[/COLOR][COLOR=#000000])[/COLOR];
                [COLOR=#0000FF]this[/COLOR].[COLOR=#000080]turret[/COLOR].[COLOR=#000080]rotation[/COLOR]=myDegrees * -[COLOR=#000080]1[/COLOR];
                [COLOR=#808080]*//this.turretbullet.rotation=myDegrees * -1;*[/COLOR]
            [COLOR=#000000]}[/COLOR]
            [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]
                [COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]**var**[/COLOR] t:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]1[/COLOR]; t<[COLOR=#000080]10[/COLOR]; t++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                    [COLOR=#000000]**var**[/COLOR] hitEnemy = [COLOR=#0000FF]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#FF0000]"targetEnemy"[/COLOR]+t[COLOR=#000000]][/COLOR];
                    [COLOR=#000000]**var**[/COLOR] hitEnemyDistX = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]abs[/COLOR][COLOR=#000000]([/COLOR]hitEnemy.[COLOR=#000080]x[/COLOR]-[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]x[/COLOR][COLOR=#000000])[/COLOR];
                    [COLOR=#000000]**var**[/COLOR] hitEnemyDistY = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]abs[/COLOR][COLOR=#000000]([/COLOR]hitEnemy.[COLOR=#000080]y[/COLOR]-[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]y[/COLOR][COLOR=#000000])[/COLOR];
                    [COLOR=#000000]**var**[/COLOR] hitEnemyDist:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]sqrt[/COLOR][COLOR=#000000]([/COLOR]hitEnemyDistX*hitEnemyDistX + hitEnemyDistY*hitEnemyDistY[COLOR=#000000])[/COLOR];
                    [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]![COLOR=#0000FF]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                        [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]hitEnemyDist<[COLOR=#000080]50[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                            [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]![COLOR=#0000FF]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                                [COLOR=#0000FF]this[/COLOR]._targetEnemy = hitEnemy;
                                [COLOR=#0000FF]this[/COLOR]._targeting = [COLOR=#000000]**true**[/COLOR];
                            [COLOR=#000000]}[/COLOR]
                        [COLOR=#000000]}[/COLOR]
                    [COLOR=#000000]}[/COLOR]
                    [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]this[/COLOR]._targeting[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                        [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]hitEnemyDist>[COLOR=#000080]50[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
                            [COLOR=#0000FF]this[/COLOR]._targeting = [COLOR=#000000]**false**[/COLOR];


                        [COLOR=#000000]}[/COLOR]
                    [COLOR=#000000]}[/COLOR]
                [COLOR=#000000]}[/COLOR]
            [COLOR=#000000]}[/COLOR]
        [COLOR=#000000]}[/COLOR]
    [COLOR=#000000]}[/COLOR]

[/LEFT]

Ok, so I’m thinking that the problem occurs with this statement. Note that this is not the full code, the syntax of the rest of the code is fine (brackets and such are there). I know this is how i wrote this is AS2, is there a new way in AS3?


for (var t:Number=1; t <= 10; t++) {
						var hitEnemy= this["targetEnemy" + t];

  • Bump * Anyone?