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.

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

BRAINhoney Beta @ NECC Conference

BRAINHoney

We will be presenting the Beta of the next wave in education at the NECC conference in Atlanta Georgia. This educational revolution is called BRAINHoney. We are excited to demo this new online collaborative learning community & the tools that bring rich multimedia lesson development into the hands of everyone, everywhere, at anytime.

If you are at NECC please come see the full demo presentation and sign up to be one of our Beta testers. We are also giving away iPods. BRAINHoney is a product of agilix inc. & can be found in the conference program. If you are not going to be at the conference & would still like to get one of the limited spots on the BRAINHoney Beta team, then please post a comment here & we will contact you.

As always Happy Flashing & Happy Learning.

Flash CS3 / Flex 2 AS3 Error #1119

Error #1119:
Access of possibly undefined property buttonText through a reference with static type flash.display:SimpleButton

or

Error #1119: Access of possibly undefined property someProperty through a reference with static type flash.display:DisplayObject.

Description:
This means that you are trying to change dynamic text nested inside a button. This is a simple fix. Just change the button to a movieClip.

Another more prevalent reason that you will get ActionScript Error #1119 is because the the new way Flash/flex handles parent objects has changed. In AS2 parent.myVar would work just fine. In ActionScript3 the compiler doesn’t know what the parent is unless specifically typed or casted instead it chalks everything up to DisplayObjectContainer. This means that it doesn’t know that the ‘parent’ is a MovieClip. The reason for this is because you can now change the object from one displayObject to another easily at compile time. You could change the parent object from a MovieClip to SimpleButton at compile time.

You also want to check your syntax to make sure that you have dynamically targeted an object correctly. For example, if you are trying to use AS3 to target a series of movieClips dynamically and each of the names start with ‘card’ and have a sequential value as well then you must use the code in Fix3 to prevent AS3 Error #1119. Fix #4 is similar to Fix 3 but Fix 4 is specific to the DisplayObject.
Fix 1:
You need to cast the parent as the type that you want or you need.

myTextField.text = MovieClip(this.parent).someVar
or
myTextField.text = (this.parent as MovieClip).someVar

One of the best explanations of casting for this error is written up by Josh Tynjala go visit his blog called “Why doesn’t the ‘parent’ property work the same in ActionScript 3”

.

Fix 2:
Rather than looking outside the movie for the variable you can push the variable into the child movieClip and then access it within itself. For example if I have a movieClip named bob that is inside of a clip named joe then I would have Joe push the variable into bob and bob would access it within himself and not need to ask his parent for the variable because he already has it.

From Joe

bob.someVar = “This is the variable”;

From Bob

myTextField.text = someVar;

Fix 3:

Bad Code:

this.card[i].id = “something”;

Good Code:

this[“card”+i].id = “something;

Fix 4:
The good code below uses a direct reference to the object that holds the property someProperty. Whereas the Bad Code example is trying to access the property through a reference through the displayObject. Because the displayObject doesn’t have the property it cannot change it.

Bad Code:

this.getChildByName(‘card’+_setClicksCounter).someProperty = true;

Good Code:

this[“card”+_setClicksCounter].someProperty = true;

Fix 5:
1119: Access of possibly undefined property nestedMovieClip through a reference with static type Class.
This is easy to fix. It just means that you are trying to access a nested object within the class statement rather than from within the Class. The problem is that the keyword “this” in the first example doesn’t references the Class itself rather the object the Class is linked to.

Bad Code:

package com.cjm.sound
{
public class SoundControl extends MovieClip
{
var _progwidth:uint = this.progBar.width;
public function SoundControl (url=null):void
{
doSomething();
}}}

Good Code:

package com.cjm.sound
{
import flash.display.MovieClip;
public class SoundControl extends MovieClip
{
var _progwidth:uint;
public function SoundControl ():void
{
_progwidth = this.progBar.width;
}}}

Related Errors:
Flash / Flex Error 1056 – You will get AS3 Error 1056 instead of 1119 if you don’t properly type your object before referencing a property on it. For example var s:Sprite = new Sprite(); s._x = 10; will give error 1119 but var s = new Sprite(); s._x = 10; will give Error 1056.

As always – 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.