Saving Processing Power [MX]

Hey all… this is a general AS question…

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.

Peace

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.

At least I think that is how it goes.

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.

hmmmmm

I’m not sure, but I do know that if you see blue smoke coming out of the back of the computer, pull the plug out of the wall… :stuck_out_tongue:

Rev:elderly:

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.

pom :cowboy:

Thanks for clearing that up Ilyas.

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 :slight_smile:

Keywords there are “certain situations”.

thanks Ilyas…

that is the type of stuff I like to know…

:stuck_out_tongue:

Rev:elderly:

Well, here is a little test I made.

this.createEmptyMovieClip("tester",0 );
a=0;
MovieClip.prototype.testing = function (){
	a++;
	a--;
	a++;
	a--;
}
start=getTimer();
for (var i=0;i < 10000;i++){
	tester.testing();
}
trace ("Time needed: "+(getTimer()-start));

This returns 1220 milliseconds average. Now this:

this.createEmptyMovieClip("tester",0 );
a=0;
testing = function (){
	a++;
	a--;
	a++;
	a--;
}
start=getTimer();
for (var i=0;i < 10000;i++){
	testing();
}
trace ("Time needed: "+(getTimer()-start));

is more like 1070 ms. And this:

start=getTimer();
for (var i=0;i < 10000;i++){
	a++;
	a--;
	a++;
	a--;
}
trace ("Time needed: "+(getTimer()-start));

returns 650. So you see what is faster now :cowboy:

Wow, that is awesome Ilyas.

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.

You don’t understand how the for loops work here?

No, I understand how they were there.

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

Oups, I pressed the wrong button.

I just meant to say that the perfect example for this would be a grid… Wanna open a new thread for a moving grid tutorial? :stuck_out_tongue:

LOL, don’t worry about answering my question.

I will figure it out sooner or later :slight_smile:

It is a stupid question anyway… I feel like a tool now :frowning:

Well, back to what I was working on :slight_smile:

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! :stuck_out_tongue:

Thanks again

Peace

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… great explanation :slight_smile:

Thanks

OOP is a pain in my arse… I have been trying to learn it, and I got some of it down, but other things aren’t clicking.

I will keep practicing though, it’s fun :slight_smile:

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?

Thanks.

Peace

i think you might want to start a new thread with that one.