0
votes

I am using Easeljs in my spare time. I tried to inherit the Container from createjs object in easeljs library.

    var innovative = {};
innovative.object = {};

innovative.object.Basic = function () {

};

//innovative.object.Basic.prototype = new createjs.Container;

innovative.object.LocalPhoto = function (data) {
};

innovative.object.LocalPhoto.prototype = new innovative.object.Basic;
innovative.object.LocalPhoto.prototype.constructor = innovative.object.LocalPhoto;

I have function in LocalPhoto which will add itself to the stage like this

innovative.object.LocalPhoto.prototype.load = function (stage, event) {
    var self = this;
            stage.addChild(self);
            stage.update();

};

This is how i create LocalPhoto object

  var self = this;
                        for (var i = 0; i < values.length; i++) {
                            this.download (values[i], function (evt) {
                                var photo;
                                photo = new innovative.object.LocalPhoto(evt.target.object);

                                photo.load(self.stage, evt);
});
}

Problem i am facing is when i add a LocalPhoto into the stage, the rest of the localPhoto within that stage will append the same photo as well.

This is what i mean in steps : 1) insert a image within a container and added to the stage. 2) another image within a new container and added to the stage. At the same time, the later image also added to the other child container which i have added to the stage.

1
Not quite get it.. I have a Basic class inherited Container then I have a LocalPhoto inherited from Basic... Somehow the previous LocalPhoto was linked with the later created LocalPhoto - LittleFunny
oh i know why ... i have to call initialize for the container...but why do we force to do that and not hidden us.. - LittleFunny
Because the initialize is similar to calling super() in traditional OOP language. JavaScript doesn’t come with super so it needs a way to initialize the inherited class. - Makzan
Oh is initialize part of javascript function or createjs class - LittleFunny

1 Answers

-1
votes
(function() {

function YourFunc(param) {
    this.Container_constructor();
    this.param = param;
}
var p = createjs.extend(YourFunc, createjs.Container);

p.draw = function() {
    this.Container_draw();
    // add custom logic here.
}

window.Button = createjs.promote(Button, "Container");
}());

Or Just

var p = YourFunc.prototype = new createjs.Container();