开发者

Error #1203: No default constructor

i'm having a hard time understanding custom events and I keep getting this same error:

1203: No default constructor found in base class flash.events:Event.

I tried to read online for a solution, but nothing helped me. I was wondering what is my error. Basically, what I want to do is create a class that will, depending of the level of difficulty (3 in total), create different objects on the scene. Here's the code:

I call it with a dispatchEvent like so:

dispatchEvent(new creationObjets(_Difficulte));

then,

package cem{
    import flash.events.*;  
    import flash.display.*;

    public class creationObjets extends Event
    {
        public function creationObjets(pDifficulte) {
            trace(pDifficulte);
        }
    }

}

I have no idea what i'm not doing wrong (or just what I am doing, period... haha). If you know the answer, maybe a little explication would help me a lot! Thank you!

*edit: i开发者_如何学JAVA just added super(pDifficulte); after the trace and no error came. I have no idea what super() does. I just did that based on examples...


You should do something like this:

public class NewClass extends Event{
    public function NewClass(type:String) {
        super(type);
        trace("whatever");  
    }   
}

The super() method calls the constructor of the Event class. You should be familiar with it if you have some knowledge about OOP. The C# equivalent is base()


The code super() runs the method in the class you are extending. In this case it would run the constructor in the Event class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜