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

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

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 #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.

Flash CS3 / Flex 2 / AS3 Error #1176

Flash CS3 / Flex 2 / AS3 Error #1176: Comparison between a value with static type String and a possibly unrelated type int.

Problem:
Flash won’t compile because it doesn’t like to compare an int with a String.

Fix:
Thank heavens for Strict Typing. Without it we wouldn’t get such nice errors. Just change the type from an “int” to a String and you will be on your way.  If you need it to really be an int then you can cast the second variable to be an int rather than a String. See code example below

Bad Code:

var dropNum:int;function bob():void
{
var myText:String = “2”;
var curNum:String = “3”;
dropNum = myText.substr(0,1);
if (curNum == dropNum) {
someCode();
}
}

Good Code:

var dropNum:String;

function bob():void
{
var myText:String = “2”;
var curNum:String = “3”;
dropNum = myText.substr(0,1);
if (curNum == dropNum) {
someCode();
}
}

or

var dropNum:int;

function bob():void
{
var myText:String = “2”;
var curNum:int = 3;

dropNum = Number(myText.substr(0,1));
if (curNum == dropNum) {
someCode();
}

Hope this helps solve ActionScript Error 1176 and Happy Flashing

Curtis J. Morley

Flash CS3 / Flex 2 AS3 Warning: #3596: Duplicate variable definition.

Warning: 3596: Duplicate variable definition.

Problem:
You are using the same variable and Flex/Flash doesn’t like it.
Fix:
Change the name of one instance or unnest your loop.

Bad Code:

var myArray1:Array = [“a”,”b”,”c”,”d”,”e”];
var myArray2:Array = [myArray1];

//This first loop goes through the parent array
for (var i:int=0; i < myArray2.length; i++)
{
//this second loop iterates through the nested array
for (var i:int=0; i < myArray1.length; i++)
{
trace(myArray2[i][i]);
}
}

Good Code:

var myArray1:Array = [“a”,”b”,”c”,”d”,”e”];
var myArray2:Array = [myArray1];

//This first loop goes through the parent array
for (var i:int=0; i < myArray2.length; i++)
{
//this second loop iterates through the nested array
for (var j:int=0; j < myArray1.length; j++)
{
trace(myArray2[i][j]);
}
}

or

var keys:String = “Word”;
for (var i:int=0; i < keys.length; i++)
{
//Code
}

for (i=0; i < keys.length; i++){
//More Code
}

Once Again – Happy Flashing

Flash CS3 / Flex 2 AS3 Error #1046

Error #1046: Type was not found or was not a compile-time constant: Name.

Description:
One reason you will get this error is if you have an object on the stage with the same name as an object in your library. So if you are trying to dynamically add a movieClip from your library that has a Class name (see image below) that is the same as the name of an instance on the stage it will give you this error. What happens when you add a class name in the library is that Flash (in this case) will create a class around that object. When you have an instance on the stage that has this same name Flash doesn’t know how to handle it because the Class was not properly instantiated.

AS3 Error 1046 Fix 1:
Remove the instance from the stage, change the name of the instance, or remove the Class linkage in your library.

Flash Error 1046: Type was not found or was not a compile-time constant:

AS3 Error 1046 Fix 2:

Import, Import, Import. Another common reason that you will get this error is because you have not imported everything you are including in your movieClip. For example if you are using textFields inside your movieClip you need to include the following line of code:

Good Code:

import flash.text.TextField;

By importing the TextField object the compiler now knows what to do with that textField inside your movieClip. This will eliminate another version of this error – ‘1046: Type was not found or was not a compile-time constant: TextField’.

Update:

AS3 Error 1046 Fix 3:

This error will also show up if you are trying to instantiate a library object with an instance name that is the same as the AS Linkage in your library. In other words, you can’t call it the same name. Look at the image for the Linkage name and then take a look at the code examples. The red code below shows that the same name is being used.

AS3 1046 Error - Library AS Linkage Name

Bad Code:

var TTA:TTA = new TTA();

Good Code:

var thirdAlternative:TTA = new TTA();

 

And now you know three ways to resolve ActionScript Error #1046: Type was not found or was not a compile-time constant:
As always Happy Flashing!

Flash CS3 / Flex 2 AS3 Error #1078

Error #1078: Label must be a simple identifier.

Description:
The main reason you will get this ActionScript error comes because of mistyping a colon. You can get AS3 Error 1078 by putting a a colon at the end of a line instead of a semicolon. You can get it by trying to ‘Type’ an object without the ‘var’ keyword, and my personal favorite – If you are in Flash writing a Class and hit the quick keys esc >> t >> r to get a trace(); statement you will get trace():void; instead.

Fix 1:
This error can be resolved by correctly typing a semicolon.

Bad Code1

myText.border = false:

Good Code1 :

myText.border = false;

Fix 2:
This can be resolved by using the keyword var. (The bad code example here is really bad code)

Bad Code 2:

this.box:MovieClip = new MovieClip();

Good Code 2:

var box:MovieClip = new MovieClip();

Fix 3:
Delete the silly extra stuff that Flash puts in there for you. If you have the bad code as shown below you will most likely get another error like 1083. Just fix the first and the second will also be resolved.

Bad Code 3:

trace():void

Good Code 3:

trace();

And that is how you solve ActionScript Error #1078

Happy Flashing

Flash CS3 / Flex 2 AS3 Error#1168

Error #1168: Illegal assignment to function setTextFormat.

This is another easy one. It just means that you assign the format within parenthesis rather than after the “=” sign.
Bad Code:

var myText:TextField = new TextField();
var myFrmt:TextFormat = new TextFormat();
myFrmt.color = 0x336699;
myFrmt.font = “Franklin Gothic Book”;
myText.text = “Flash is fun – Happy Flashing Everyone”;
myText.border =true;
myText.wordWrap = true;
myText.autoSize = TextFieldAutoSize.CENTER;
myText.setTextFormat = myFrmt;
this.addChild(myText);

Good Code:

var myText:TextField = new TextField();
var myFrmt:TextFormat = new TextFormat();
myFrmt.color = 0x336699;
myFrmt.font = “Franklin Gothic Book”;
myText.text = “Flash is fun – Happy Flashing Everyone”;
myText.border =true;
myText.wordWrap = true;
myText.autoSize = TextFieldAutoSize.CENTER;
myText.setTextFormat(myFrmt);
this.addChild(myText);

And this is how you resolve Error #1168: Illegal assignment to function setTextFormat.

Flex2 Builder not installing on Vista

So for all you people that jumped on the Windows Vista bandwagon you may be experiencing difficulty running Flex2 Builder after you have installed it.

This is the error that I was getting:

!SESSION 2007-05-11 20:10:31.205 ———————————————–
eclipse.buildId=unknown
java.version=1.4.2_12
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86

!ENTRY org.eclipse.update.configurator 2007-05-11 20:10:31.696
!MESSAGE Cannot backup current configuration

!ENTRY org.eclipse.update.configurator 2007-05-11 20:10:31.727
!MESSAGE Could not rename configuration temp file

!ENTRY org.eclipse.osgi 2007-05-11 20:10:32.644
!MESSAGE Application error
!STACK 1
java.lang.UnsatisfiedLinkError: no swt-win32-3139 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:123)
at org.eclipse.swt.internal.win32.OS.(OS.java:18)
at org.eclipse.swt.widgets.Display.(Display.java:125)
at org.eclipse.ui.internal.Workbench.createDisplay(Workbench.java:381)
at org.eclipse.ui.PlatformUI.createDisplay(PlatformUI.java:155)
at com.adobe.flexbuilder.standalone.FlexBuilderApplication.run(FlexBuilderApplication.java:45)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)

!ENTRY org.eclipse.osgi 2007-05-11 20:10:32.647
!MESSAGE Bundle
update@plugins/com.adobe.flexbuilder.debug.e32_2.0.155577/ [70] was not resolved.
!SUBENTRY 1 org.eclipse.osgi 2007-05-11 20:10:32.647
!MESSAGE Missing required bundle org.eclipse.debug.ui_[3.2.0,99.0.0).

And this is how to resolve it:

I experienced the same issue when I tried to install Flex on a new Vista system. Here’s how I corrected it:

1) Navigate to C:\Program Files\Adobe\Flex Builder 2\plugins

2) Look for the file “org.eclipse.swt.win32.win32.x86_3.1.2.jar”. You will need to open this in a file compression program such as WinAce, WinRar or WinZip. If you don’t have such a program you can try:

2a) Copy (make sure you COPY, not MOVE) the file to another location, such as your desktop.

2b) Rename the file with a “.zip” extension (i.e. change “.jar” to “.zip”). NOTE: You will not see the file extension if your system is configured to hide extensions. In this case, open a Windows Explorer window (“My Computer”, etc.) and press the “Alt” key. A menu bar will appear. Select “Tools -> Folder Options”. Select the “View” tab, and look for “Hide extensions for known file types”. Uncheck the box, then click OK.

2c) You should now be able to right-click the file and use Vista’s built-in .zip extraction to extract the contents to a folder.

3) Within the org.eclipse.swt.win32.win32.x86_3.1.2.jar file is a file called “swt-win32-3139.dll”. Copy this file to C:\Windows\System32\ (You will be asked for a confirmation when you do this).

Once that is done, Flex should run correctly. You can now delete the copy of the .jar file that you made, as well as the folder created by Vista’s .zip extraction (if applicable).

Hope this helps!

The above excerpt was taken from the following website at Adobe

http://www.adobe.com/cfusion/webforums/forum/rss.cfm?forumid=60&catid=539

As always Happy Flashing/Flexing