开发者

trouble while writing a var for function

I trying to to a function like this, but it couldn't work. could you have a look on this ^^

var test:testMc;

addMonster(test,testMc);

public function addMonster($mon:MovieClip,$mon开发者_Go百科Mc:MovieClip)
{$mon= new $monMc(stage, enemy);
}

Line 3 - 1067: Implicit coercion of a value of type Class to an unrelated type flash.display:MovieClip.

Line 6 - 1180: Call to a possibly undefined method $monMc.

How can I fix it?

Thank you for your help ^^


In the future you should have posted more code and told us which lines those errors were on, because in this case we can't see where you declared testMc or the line numbers. Fortunately in this case it doesn't matter because I can see the problem at a glance.

The second parameter in addMonster() is typed MovieClip when in fact the object is a Class. That is the cause of both error messages. Your code should be something like:

public function addMonster($mon:MovieClip,$monMc:Class)

Incidentally, I'm very curious why you would write code like this. I guess this could be a small snippet from some sort of factory class, but at a glance this looks like a pretty goofy way to instantiate an object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜