MX: OOP and Mc's!

Hoi

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:

G i hope that this all adds up:-\

are you trying to do a movieclip-subclass?

Yeah:beam: (i think:-)

but i am new to all this oop stuff

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

WELL =)

i will look into that :thumb:

the Q’s will be going soon :wink:

*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

Hoi

what does call(); do i can’t find it in the flash help and there is nothing on it in http://www.debreuil.com/docs/ch01_Intro.htm

and constructor?

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).

Thanks :}

still a little :q:

but too a :sleep: to think much more

I am going to bed

ThanksThanksThanks=)

Hoi

so what this does
is changes the prototype of the someName to the prototype of newMc
and newMc’s prototype is a new MovieClip!

am i right?

yeah more or less :wink:

read through this
http://www.flashkit.com/board/showthread.php?s=&threadid=462834

faints

hoi

:}

ok i read your post :wink:

and i found this http://userpages.umbc.edu/~tmccau1/...pcreatures.html
it saw going to be my next Q

i will understand all this OOP over time (hope!!)

Thanks for all your help

P.s if i may ask?
how lang did it take you (sen) to learn OOP?