Flash compiler error 1061: Call to a possibly undefined method run... but run exists!
So I've been working on making a game in Processing but I think Flash would be a better way to get more people playing it, so I've decided to learn Flash. The problem is that I keep getting really stupid errors on incredibly simple things. For instance, I want to make a 'Block' object to use in a platform game. So I make a new .as file, name it Block.as, and define the Block class within it like so:
package {
public class Block {
public function Block() {
// constructor code
}
public function run()
{
}
}
}
I don't want to add the code yet, I just want to ensure that this works. So in my main timeline code, I try to create an instance of the Block object and execute its run method:
var block1:Block = new Block();
block1.run();
Every time it gives me this inane error:
Scene 1, Layer 'Layer 1', Frame 1, Line 2 1061: Call to a possibly unde开发者_JAVA技巧fined method run through a reference with static type Block.
What undefined method!? It's defined RIGHT THERE in Block.as. The class file is even in the same folder and everything. I'm getting REALLY annoyed at how poorly Flash handles such a ridiculously simple project. Does anyone know why Flash hates me?
You didn't declare a return type for run.
public function run():void
{
add :void to the signature.
Edit to add --
It wasn't always like this, by the way. You may have read tutorials that completely omit return types and strongly typed variables. In older versions of the Flash IDE you could freely omit them. In CS5 you no longer can do this without disabling Strict mode. You probably should leave strict mode on.
精彩评论