PDA

View Full Version : MX: OOP and Mc's!!



Johnny64
August 1st, 2003, 02:18 PM
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:-\

ahmed
August 1st, 2003, 02:22 PM
are you trying to do a movieclip-subclass?

Johnny64
August 1st, 2003, 02:28 PM
Yeah:beam: (i think:-\)

but i am new to all this oop stuff

senocular
August 1st, 2003, 02:46 PM
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

Johnny64
August 1st, 2003, 02:52 PM
WELL =)

i will look into that :thumb:

the Q's will be going soon ;)

h88
August 1st, 2003, 03:06 PM
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?

senocular
August 1st, 2003, 03:11 PM
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

Johnny64
August 1st, 2003, 04:07 PM
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__?

senocular
August 1st, 2003, 04:34 PM
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).

Johnny64
August 1st, 2003, 04:41 PM
Thanks :}

still a little :q:

but too a :sleep: to think much more

I am going to bed

ThanksThanksThanks=)

Johnny64
August 2nd, 2003, 01:28 PM
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?

senocular
August 2nd, 2003, 01:55 PM
yeah more or less ;)

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

ahmed
August 2nd, 2003, 01:57 PM
*faints*

Johnny64
August 2nd, 2003, 02:57 PM
hoi

:}

ok i read your post ;)

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?