is there a way to make a mc belang to a new object like this (but this doesn’t work)
newMc = function () {
this.createEmptyMovieClip("new_mc", 0);
};
Mc1 = new newMc()
// and i tryed this
newMc = function () {
this = new MovieClip();
this.createEmptyMovieClip("new_mc", 0);
};
Mc1 = new newMc()
i know i can do it like this
newMc = function () {
_root.createEmptyMovieClip("new_mc", 0);
};
Mc1 = new newMc()
but now i and makeing a new object and a new Mc but they are not in the same… thay have nothing in commen!!
its
_root.Mc1 and _root.new_mc
and not Mc1.new_mc :sigh:
theres no standard way of associating an empty movieclip with a class, you’d need to alter its proto
newMc = function () {}
newMc.prototype = new MovieClip();
_root.createEmptyMovieClip("someName", someDepth);
someName.__proto__ = newMc.prototype;
newMc.call(someName); // if the constructor added any properties
*Originally posted by senocular *
**theres no standard way of associating an empty movieclip with a class, you’d need to alter its proto
newMc = function () {}
newMc.prototype = new MovieClip();
_root.createEmptyMovieClip("someName", someDepth);
someName.__proto__ = newMc.prototype;
newMc.call(someName); // if the constructor added any properties
**
Sen, can’t we just make someName an instance of newMc? I mean, it’s not really reliable to edit the proto property when you can use the ‘new operator’ instead, Knowing it will also invoke the constructor without the need of call?
the thing is any new newMc wont be a movieclip. You can make it a normal object and give it a movieclip as a property, but it wont be the movieclip object - just an object with a movieclip for a property. For an empty movieclip to be an instance of a class, since it has no association with Object.registerclass, you’d need to alter its proto reference. Then that movieclip would have access to that class’s prototype and methods.
There’s a good discussion about proto and what really happens there and what it does in some of the links posted in the best of senocular. Worth checking out if you havent seen them already
call runs a function. Basically its a different format of calling a function.
functionName.call(objectName)
instead of
objectName.functionName();
The big difference is that in that second example, objectName.functionName(); for objectName to run functionName, that function has to be defined in or exist in objectName (or it needs to be accessible through a prototype). With call, that doesnt need to be the case. Because of that, it allows you to run the myMc constructor function in the scope of the empty clip instance without having to assign it to exist within that clip, since, as I said before, theres no direct method of associating a class with an empty clip.
constructor is used in correcting super. I didnt include that in the first code sample because I didnt think you needed to worry about it and things were probably confusing enough then as it was. Basically, what it does is allow super to correctly reference the right superclass when called. You can read more about super in the best of senocular links (and the constructor is mentioned there).