-
Notifications
You must be signed in to change notification settings - Fork 1
Common Problems
- Error: Call to a possibly undefined method X
- TypeError: Error #1009: Cannot access a property or method of a null object reference
- Application Mediator not instantiated
Among other reasons this error could be the result of not following the AS3 naming conventions for packages, classes, methods, variables, and so on.
For example something like this:
package controller { import model.MyModel; import org.robotlegs.mvcs.Command; public class MyCommand extends Command { [Inject] public var model:MyModel; [Inject] public var event:MyEvent; override public function execute():void { model.myMethod(); } } }
would result in: Error 1180: Call to a possibly undefined method myMethod
and eventually a warning (depending on the SDK):
Warning 3599: Definition name is the same as an imported package name.
Unqualified references to that name will resolve to the package and not the definition. If a definition is named the same as a package that is in scope, then any unqualified references to that name will resolve to the package instead of the definition. This can result in unexpected errors when attempting to reference the variable. Any references to the definition need to be qualified to resolve to the definition and not the package.
This would be incorrect: model.SomeModel
This would be better: domain.project.area.model.SomeModel
It wouldn’t hurt to read the Coding Conventions again (and again).
-
I found this answer in http://forums.adobe.com/message/34078#34078:
This is not a bug. We allowed this in CS3, but it was actually unintended. In CS4, we follow the ecma specification which state that imported package names shadow names of definitions in the same scope when used on the lhs of a dot operator (ie they look like package references). Workarounds include wrapping the reference in parens.
e.g.
import mypackageorclass.*
class mypackageorclass {}
mypackageorclass.x // to refer to the package
(mypackageorclass).x // to refer to the class
In your case, it is a local variable that is ambiguous with the package, but you should be able to use the parens workaround.
I tested parens on the local variable, it still references the package, so best-practice is to always ensure full package namespaces like com.myapp.test
Simply put, when a TypeError exception like the above is thrown, it means that you are trying to reference something that isn’t there (yet).
There are many situations that can lead to such an error, but while using robotlegs a common mistake is:
The object you are trying to reference hasn’t been injected because
- see “Injection Doesn’t Occur“:http://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems#no-injection
- you are not casting your Objects / Classes correctly
- you are trying to access a property too soon, i.e. the property will not have been injected yet (check the mapping order, make sure your context has been initialized before adding Views to the display list)
- you forgot to add the metadata tag [Inject]
- [Inject]
private var someClass:SomeClass;
Injected values have to be public
- or you misspelled it:
Wrong:
[inject]
[InJect]
[INJECT]
Right:
[Inject]
public var someClass:SomeClass;
More info about TypeError
Take a look at:
1. Problem: Injection Doesn’t Occur