Flash/Flex AS3 Error #2007

Error #2007: Parameter text must be non-null.It is the error of the year Error 2007. This error is very ambiguous but is not hard to understand once you realize what it means.

This error means that you are trying to assign an object some text but you forget to target the text and instead you target the text field. In the bad example below ‘.text’ is forgotten. It is included in the Good Code

Bad Code:

for (var i:int = 0; i<15; i++) { array[i] = myText_txt;
}

Good Code:

for (var i:int = 0; i<15; i++) { array[i] = myText_txt.text;
}

And that is how you solve ActionScript Error #2007: Parameter text must be non-null.

As always Happy Flashing

Nike+ 100 Mile Club

I am very excited to share with you that I have made the 100 mile club on Nike+.

Here is the proof Nike+ 100 Mile Club

Nike+ iPod is an amazing system. If you are contemplating it, you should stop thinking about it and go right now and get one. In high school I did sprints and short distance on the track team. I tried out for the cross country team and promptly quit after 2-3 weeks. I loved to sprint in the 100, 200, and would even do the 400. I was on relay teams and my best event was the long jump. I tell you this to let you know how much I was not a long distance runner. I actually expressed my disinterest in running many times over the years. If you were to tell me that I would run a hundred miles in a few months I would have thought you were crazy. That is until I got the Nike+ system. Now I run and run and just keep going. Nike+ is probably the biggest reason that I have turned into a runner. The system is amazingly easy to use and eliminates all the work that you have to do. Instead of getting out the spreadsheets and tracking progress, I now just sync my iPod nano and it uploads all my workouts, charts them, applies them to the goals I have set and challenges that I have joined and shows me progress, calories, distance, time, pace, etc, etc…

The last two big plugs for Nike+ is that the website is killer and the community that the website is built around is amazingly supportive. I never considered myself a runner like my neighbor or friends, but now I am actually starting to think that maybe I am one. Thanks Nike+ iPod and thanks to the community that support me.

Happy Running

Flash CS3 / Flex 2 Error #1084

ActionScript Error #1084: Syntax error: expecting rightbrace before end of program.

Error 1084 is the general error number for syntax errors. ActionScript Error #1084 can be any number of errors. I will keep this one up to date with all the variations I find and how to fix them.

AS3 Error 1084: Syntax error: expecting rightbrace before end of program

This is a very easy one. This error just means that you are most likely missing a right brace. Or you have nested code improperly.

Bad Code:

package com.cjm
{
class CoolClass {
function CoolClass () {
trace(“Something cool”)
}
}

Good Code:

package com.cjm
{
class CoolClass {
function CoolClass () {
trace(“Something cool”)
}
}
}

Please make note of the third bracket at the end of the good code.

ActionScript Error #1084: Syntax error: expecting colon before semicolon.

You will most likely get this error if you are using a ternary statement and you forget to use a colon, forgot the last part of your ternary, or you replace the colon with a semicolon. This is illustrated in the following example:

Bad Code:

me.myType == “keys” ? trace(keys);

or

me.myType == “keys” ? trace(keys) ; trace(defs);

Good Code:

me.myType == “keys” ? trace(keys) : trace(defs);

Flash/Flex Error #1084: Syntax error: expecting identifier before leftbrace.

Description:
This Flash/Flex Error is reported when you left out the name of your class. The ‘identifier‘ that it is looking for is the name of your class.

Fix:
You will see in the code below that you just need to add in the name of your class and the error will go away.

Bad Code:

package com.cjm.somepackage {
public class {
}
}

Good Code:

package com.cjm.somepackage {
public class MyClass {
}
}

Flex/Flash Error #1084: Syntax error: expecting leftparen before colon.
or
Flex/Flash Error #1084: Syntax error: expecting rightparen before colon.

Description:
These AS3 Errors are reported when you the order of the parenthesis and colon are not in the proper place or the parenthesis is missing.

Fix:
The AS3 code below demonstrates the placement error. Properly order the items and the error will disappear. Also, make sure that a parenthesis is not missing. The ‘Bad Code’ gives an example of leftParen and then right paren in the order.

Bad Code:

public function ScrambleSpelling:void (s:String)
or
public function ScrambleSpelling(s:String:void

Good Code:

public function ScrambleSpelling (s:String):void

Flex/Flash Error #1084: Syntax error: expecting rightparen before semicolon.

Description:
This AS3 Error is reported most often when the parenthesis is missing.

Fix:
Make sure that a parenthesis is not missing. The ‘Bad Code’ gives an example of leftParen and then right paren in the order.

Bad Code:

tempArray.push((middle.splice(middle.length-1) * Math.random());
or
tempArray.push(middle.splice(middle.length-1) * Math.random();

Good Code:

tempArray.push(middle.splice(middle.length-1) * Math.random());

Flex/Flash Error #1084: Syntax error: expecting identifier before 1084.

Description:
This AS3 Error is reported when you have begun a package, class, function/method or variable with a numeric character rather than an Alpha character, _(underscore), or $(dollar sign).  In the Flash Authoring environment it won’t allow you to add numerics as the first character in an instance name or in the linkage but with code it just gives this crazy error.

Fix:
Make sure to name your package, class, function/method or variable with a Alpha character, _(underscore), or $(dollar sign).

Bad Code:

package 1084_error
{
class 1084_error {
function 1084_error () {
var 1084_error:int = 123;
}
}
}

Good Code:

package error_1084
{
class error_1084 {
function error_1084 () {
var error_1084:int = 123;
}
}
}

P.S.  It is probably not a good idea to give everything the same name as in the examples above.

AS3 Error #1084 will rear it’s many heads according to the particular syntax error at the moment. I will post every variation of this error that I can find.

Once again Happy Flashing

Test Code

ActionScript 3 Error #1017: The definition of base class ImportedClass was not found.

You may get this error from importing a custom class that does not have the proper package path into a parent class. Another reason you will get this error is if you forget to import the Class that the subclass is extending(see example 2).

Bad Code 1
(subClass called ImportedClass)

package
{
import flash.display.MovieClip;
public class ImportedClass extends MovieClip
{
public function ImportingClass()
{
trace("Message");}}}

Parent Class called ImportingClass

package com.cjm
{
import flash.display.MovieClip;
import ImportedClass;
public class ImportingClass extends MovieClip
{
public function ImportingClass()
{
trace("Message");}}}

Flash CS3 / Flex 2 Error #5001

ActionScript Error #5001: The name of package ‘com.cjm’ does not reflect the location of this file. Please change the package definition’s name inside this file, or move the file

Description:
This ActionScript error is a very common one especially if you haven’t defined a good package and class structure. The simple answer is that you misspelled something in your package description or you saved the class in the wrong folder. (See example 1)

Another reason that you can get this error in Flash is because you have a Document Class and you have specified the classpath in the “Document class:” field and you have something different typed in your package. You might say well that is not possible. If your default classpath is defined in the AS3 setting then the file will compile and the class will work properly if you remove the classpath all together out of your package. This is not recommended because it is not good practice. Please review the example2 below.

Solution:
Check your paths in the package, class and ‘Document Class’.
Example 1

Bad Code

package com.ckm
{

}

Good Code

package com.cjm
{

}

Example 2

Good Code – Bad “Document class:” definition

package com.cjm
{
public class MyDocClass
{
public function MyDocClass()
{
}}}

Flash Document Class Path Bad Example

Good Code – Good “Document class:” definition

package com.cjm
{
public class MyDocClass
{
public function MyDocClass()
{
}}}

Flash Document Class Path

And those are two ways to resolve ActionScript Error #5001

As Always – Happy Flashing

Flash CS3 / Flex 2 Error #1017

ActionScript 3 Error #1017: The definition of base class ImportedClass was not found.

Description 1
You may get this error from importing a custom class that does not have the proper package path into a parent class. Another reason you will get this error is if you forget to import the Class that the subclass is extending(see example 2).

Bad Code 1
(subClass called ImportedClass)

package
{import flash.display.MovieClip;
public class ImportedClass extends MovieClip
{
public function ImportingClass()
{
trace(“Message”);}}}

Parent Class called ImportingClass

package com.cjm
{
import flash.display.MovieClip;
import ImportedClass;
public class ImportingClass extends MovieClip
{
public function ImportingClass()
{
trace(“Message”);}}}

Good Code 1

(SubClass called ImportedClass)

package com.cjm
{
import flash.display.MovieClip;
public class ImportedClass extends MovieClip
{
public function ImportingClass()
{
trace(“Message”);}}}
ImportingClasspackage com.cjm
{
import flash.display.MovieClip;
import ImportedClass;
public class ImportingClass extends MovieClip
{
public function ImportingClass()
{
trace(“Message”);}}}

Bad Code 2

package com.cjm
{
//import flash.display.MovieClip;
public class ImportedClass extends MovieClip
{
public function ImportingClass()
{
trace(“Message”);}}}

Good Code 2

package com.cjm
{
import flash.display.MovieClip;
public class ImportedClass extends MovieClip
{
public function ImportingClass()
{
trace(“Message”);}}}

Description 2
ActionScript Error #1017: The definition of base class MovieClip was not found.
This ActionScript Error is due to forgetting to import the MovieClip (or any other  referenced class).

Bad Code 3

package com.cjm.sound
{
public class SoundControl extends MovieClip

Good Code 3

package com.cjm.sound
{
import flash.display.MovieClip;
public class SoundControl extends MovieClip

As always – Happy Flashing

Flash CS3 / Flex 2 Error #1502:

Error #1502: A script has executed for longer than the default timeout period of 15 seconds.

Problem:
You have entered the realm of “Flash Infinite Loop” or at least a really long loop. This is very common when running loops, especially do…while loops.  The timeout is now set to 15 seconds (see image below).

ActionScript Error 1502

Fix:
Make sure that you are not executing a loop that will never break out. Those poor loops running in circles for all of us Flashers/Flexers.

*******************Warning*******************
The Bad Code below will send your Flex/Flash into and infinite loop and will potentially crash your Development Tool. DO NOT COPY and PASTE the BAD CODE EXAMPLES BELOW.

Bad Code:
var myLength:int = 2;

for (var i:int = 0; i < myLength ; i–);
trace(i);
}

Good Code:
var myLength:int = 2;

for (var i:int = 0; i < myLength ; i++);
trace(i);
}

The code examples above have the var i starting with a number that is smaller than the number it is trying to iterate to. This code basically says as long as i is smaller than myLength then loop and each time I loop make i even smaller.

Bad Code:
*********This code crashed my Flash multiple times.*******

var myArray:Array = [“joe”, “bob”,”pam”];
var randNum:int = Math.round(Math.random()*myArray.length-1);
var curNum:int = 1;
do {
trace(randNum);
} while (randNum == curNum);

The key to using do…while loops in Flash is to make sure that the variable that you are validating against is changed inside the loop itself. Unless the variable that you are validating against changes within the loop itself it will loop forever. This example of a do…while loop is valid but will very likely put Flash into an infinite loop because the likelihood that the number will be 1 is very high, especially considering that the code is rounding and the number 1 is the middle digit of the three. This loop can execute quickly if Flash happens to choose another number or it can loop infinitely. The reason you might be doing this kind of loop is because you want to pull things out of an array, xml, or some other list and don’t want to get duplicates. A better way to do this is to either use the splice() methods in Flash or Flex or if you don’t want to affect the original array you can slice() out a duplicate without the curNum value and then the value will never be repeated because it no longer exists in the items that you are evaluating against. That way you know for sure the item that you don’t want repeated is gone.

There are many other ways to run into an infinite loop. These are just a couple. Feel free to post any questions you have in the comments section and I will answer them promptly.

Thanks and Happy Flashing.