Mootools 1.6 Subclass initialize method is not called

81 views Asked by At

I'm using mootools 1.6. I based my code on their tutorial but when I try to run it, the initialize function of my subclass is not invoked. Instead, it goes directly to the parent class' initialize function. I tried breakpointing inside the subclass initialize function but it really doesn't go there. In fact, my additional functions are also undefined. It's like only the functions of the parent class are created. :(

Here's my sample code:
parent.js

   var Parent = new Class({

    initialize: function(){
        alert("parent");
    },
    ...

});


child.js

var Child = new Class ( {
    Extends: Parent, 
    initialize: function () {
        this.parent();
        alert("child");
    },
    ... some additional functions
});


1.) Note that they are in different js files.
2.) These files are preloaded by cocos2d-js

    ...
    "src/controllers/parent.js",
    "src/controllers/child.js",
    ...
1

There are 1 answers

2
cessmestreet On BEST ANSWER

I was able to solve this issue. There's no issue with Mootools. It was how I used it. I'm posting it for people who might encounter the same issue.

I have 3 js files.

parent.js
child.js
orphan.js (calling it orphan hahaha)

These 3 files are added to project.json in that order. I'm not using orphan.js. I thought I already removed it from the list but I was wrong. :(

Inside orphan.js, is a class. This class uses the same name as the class inside child.js. It's empty and is just extending the parent. What happened was, it redefined the object since it's loaded after child.js. I switched their order to see if it will use child.js declaration instead and indeed, it did. But that's not the solution. I just used it to prove that it was redefined. The solution was to remove that file from source / make sure no classes have the same name.

Whew. false alarm.