Skip to main content
August 19, 2010
Question

Error #1065 on Variables that Exist

  • August 19, 2010
  • 3 replies
  • 3574 views

I was working on a project in CS3 and since i'm getting closer to completion i started porting it to CS4 flashplayer 10. (bug is also present in CS5 when exporting for flash player 10.) Whenever i run the project this line is displayed: ReferenceError: Error #1065: Variable $elementInstruction is not defined. along with the stack.

To start off with the Class "IS" defined "PUBLIC" (though not in capitals). The area i am getting the problem is in the below code snippet:

Origional Code:

protected function digestString($instructions:String):void
        {
            var $instanceNameCommands:Array = $instructions.split("$");//String("owner-player_modifier-armor_modifier-speed_units-78").split("_");
            for (var i:Number = $instanceNameCommands.length - 1; i >= 0; i-- )
            {
                var $elementInstruction:Array = $instanceNameCommands.split("_");
               
                switch($elementInstruction[0])
                {

The Above code is the one i started with. The first variable to get the "Error #1065" was the  $instructions variable, my fixes are in the below code, then the $instanceNameCommands var. the last var $elementInstruction was even a bigger problem b/c even after i made the modifications it still doesn't work???

Modified:

     public function digestString($instructions:String):void
     {
            var $instanceNameCommands:Array = ($instructions as String).split("$") as Array;//String("owner-player_modifier-armor_modifier-speed_units-78").split("_");
            trace(($instanceNameCommands as Array).length)
            for (var i:Number = ($instanceNameCommands as Array).length - 1; i >= 0; i-- )
            {
                var $elementInstruction:Array = (($instanceNameCommands as Array) as String).split("_") as Array;
               
                switch($elementInstruction[0] as String)
                {

I don't know if this is related but the $instructions var is coming from var this.name where the class extends movieclip.

Any assistance that you provide would be greatly appreciated,

bnns

This topic has been closed for replies.

3 replies

Inspiring
August 19, 2010

To start with, this code is more efficient:

public function digestString($instructions:String):void
{
     var $instanceNameCommands:Array = $instructions.split("$");
     trace($instanceNameCommands.length);
     var $elementInstruction:Array;
     for (var i:int = 0; i < $instanceNameCommands.length; i++)
     {
          $elementInstruction = String($instanceNameCommands).split("_");
          switch($elementInstruction[0] as String)
          {
               
          }
     }
}

August 19, 2010

That was how my code looked before i started tweaking it to fix the errors...casting seemed like the only thing that worked. heh

Inspiring
August 19, 2010

Just noticed.

THe line:

  for (var i:Number = ($instanceNameCommands as Array).length - 1; i >= 0; i-- )

the last i will be -1 - it will cause problem for the lowest array index is 0.

Also, why bother with decrementing if you can do it a more conventional way:

for (var i:int = 0; i < $instanceNameCommands.length; i++ )

In addition, there is no need to cast  $instanceNameCommands to Array for it was declared as Array.

August 19, 2010

3) I agree that i shouldn't have to cast the stupid var but i've been getting those errors and casting seemed like the only thing that was fixing them.

2) I don't increment out preference for this particular code snippet i don't remember it had to do with the order in which the information is read in by the code b/c it's based off the instance name of an mc it much easier to append information at the beginning than at the end.

1) From what i understand this line of code will run from designate # to as long as it is greater that or equal to 0 which means -1 should never go through, i could have rewrote it like this:   for (var i:Number = ($instanceNameCommands as Array).length - 1; i > -1; i-- ) and it would still have the same functionality.

Inspiring
August 19, 2010

i could have rewrote it like this:   for (var i:Number = ($instanceNameCommands as Array).length - 1; i > -1; i-- ) and it would still have the same functionality.

I doubt it. With this loop when i == 0 - it will still decrement it and the last i will be -1. It is easy to test. Why don't you trace i?

Inspiring
August 19, 2010

Your CS4 and CS5 compilers have a strict mode (which is a good thing) - this is why you started getting these errors while transitioning.

What are the line numbers for the errors? (enable/permit debugging in publish settings) And what is the code on the line that corresponds to the error?

August 19, 2010

Strict Mode is Disabled currently and Debugging is permitted.

The error started off as this line: var $instanceNameCommands:Array = $instructions.split("$");

Inspiring
August 19, 2010

Are you still getting 1065? If so, post entire stack.