10.08.12

Flash Error #1006: addEventlistener is not a function.

Posted in Flash at 6:48 am by Curtis J. Morley

ActionScript TypeError: Error #1006: addEventlistener is not a function.

Description:
This ActionScript error is wonderfully simple. It comes from calling something that you think is a function but Flash doesn't recognize as such. Error #1006 can pop up for a different reason too. Make sure to see my first post on AS3 Error 1006 if the answer below doesn't solve it for you.

Fix:
Look closely at the code above. In my case I just misspelled the native call to add an event listener. I typed addEventlistener with a lower case "l" instead of "addEventListener" with "L" capitalized. The fix is just to spell it correctly.

Bad Code:

blackBarFull_mc.addEventlistener(TouchEvent.TOUCH_TAP, navBack);

Good Code:

blackBarFull_mc.addEventListener(TouchEvent.TOUCH_TAP, navBack);

Easy Error, Easy Fix.

Related AS3 Error:
Flex / Flash Error #1006 value is not a function

As always Happy Flashing

Curtis J Morley

10.07.12

Flex / Flash TypeError: Error #1006: value is not a function.

Posted in Adobe, Error, Error, errors, Flash, Flash CS5.5, Flash CS6, Flex, quicktip at 5:46 am by Curtis J. Morley

ActionScript Error #1006: A user-defined namespace attribute can only be used at the top level of a class definition.

Description:
This ActionScript error will pop-up when a namespace is declared anywhere besides the class definition. What is a class definition you ask? It is simply the code that names the class - something like 'public class MyClass'

After the class is defined you are allowed to create custom(or 'user-defined') namespace on that level. Anywhere else in the code is not legal. This ActionScript Error is closely related to the Flash/Flex error #1114.
This AS3 error may also just be a typo. you may have typed something like 'publi class' rather than 'public class' or 'prvate function' rather than 'private function'

Fix:
Either fix the misspelling in your code or place the 'user-defined namespace' inside the class definition. The second code example shows a namespace to separate cars and animals. Notice how the bad example nested the 'user-defined namespace' inside the constructor function.

Bad Code 1:

package com.cjm.somepackage
{
publi
class MyClass {
publi
function MyClass() {}
}
}

Good Code 1:

package com.cjm.somepackage
{
public
class MyClass {
public
function MyClass() {}
}
}

Bad Code 2:

package
{
public class MyClass
{
public namespace Cars;
public namespace Animals;

public function MyClass()
{
Animals var Jaguar:String = "A large cat chiefly of South America";
Cars var jaguar:String = "A large car chiefly driven in North America";
}

Cars function run():void {
trace("At $30/mile");
}

Animals function run():void {
trace("On four legs");
}
}
}

Good Code 2:

package
{
public class MyClass
{
public namespace Cars;
public namespace Animals;

Animals var Jaguar:String = "A large cat chiefly of South America";
Cars var jaguar:String = "A large car chiefly driven in North America";

public function MyClass()
{

}

Cars function run():void {
trace("For 100,00 miles");
}

Animals function run():void {
trace("On four legs");
}
}
}

Adobe has a great explanation of how to use namespaces as well as Collin Moock in Essential ActionScript 3 in Chapter 17

Related AS3 Error:
Flex / Flash Error #1006 addEventlistener is not a function

As always Happy Flashing