Lets say I have an MC that occurs many times on the stage, and each one has a motion, and random scaling script in it. Would I save computing power by not having a script in each MC but rather assign them all to a prototype? Just wondering.
Yes you would. Because if you put the function on each clip seperately, Flash has to read each of those. Where if you contain it in one prototype, then it only reads it once.
I thought that too, but the only reason I wonder is this…
if there are 10 MCs with that script Flash is executing each script 1 time for a total of 10 times (once for each MC). If there is a prototype then Flash is executing one script, but doing it 10 times (once for each MC)… this thought keeps me scratching my head.
I am not sure if this makes them equal in processing use, but it sounds right… I dunno.
HAHAHA, I am pretty sure in one way or another prototypes save more on processor power than putting code on each and every button.
Not sure it does a noticeable amount of good, but I swear I remember reading somewhere that it helps to use prototypes. I heard it is better to use prototypes than functions for that reason too :-\
I could be wrong, maybe my mind is playing tricks on me.
You’d have to make tests to know that, syntax. Set a timer, and do an instruction 5000 times with each method.
And sorry to disappoint you guys, but usually prototypes are slower than anything else. They are just practical for certain things, necessary for others, but not fast.
I remember where I heard about prototypes being a better choice.
I heard it from bit on his forum. Someone asked what was so great about prototypes, and Bit told him that in certain situations, prototypes are much better to call upon rather than calling on regular functions
I really don’t understand a lot about those for loops though :-\
I try and I try, but when duplicating objects with the for loop I get all screwed up again because I don’t know how to assign specific “properties” to each clip, it always ends up applying it to just that last one added.
But like when you use for loops to duplicate movie clips and such, if you want to set a different property for each of the clips duplicated instead of just on the last one it duplicates.
Is that possible (probably, but I can’t get it to work).
Thanks for all the detailed info Ilyas!! Really helped clear some stuff up for me, but also raised more queries for me… you know what answers are good for? creating more questions!
as i said in the other thread, prototypes save you memory. i never said they save speed.
a prototype is one function that all members of that class share, rather than each member having its own copy.
now, personally, i don’t see a problem in the immediate future of running into memory problems in flash. you’d have to have a lot of objects with a lot of big functions. but from a “best practices” standpoint, it makes more sense to make one function and share it.
any time you use any function, there is overhead. rather than just saying, “do these following commands” you are saying, “evaluate this variable to a function reference, find that function, and then execute the commands in it.” prototypes may be even worse because you are saying, “evaluate this variable- oh, it doesn’t exist in this object, ok, check this object’s prototype. yup there it is, ok, evaluate it to a function ref, then find that function and execute the commands.”
but, as pom demonstrated, you should always test before you choose.
oop concepts are a style of coding that is meant to make programming large projects easier, particularly in changing and reusing the code. it’s selling point has never been fast efficient code.
Hey bit, maybe you (or Ilyas, or anyone who can help) could look at something for me and tell me what you think. goto www.intl-importers.com
Notice the animated "I"s in the top right… this is an MC with different instances of an I with a code in each one that animates it then resets it at a random size and alpha.
If you scroll over the main menu buttons of the site and watch the animation sometimes it pauses for a bit. I have even removed many of the "I"s I had origonally and it still slows up a bit. This became more noticable when I added sound to the menu buttons.
Any thoughts on why this might be, and what you think the best way to go about making it smoother might be?