PDA

View Full Version : what is better/more efficient would you say?



kamcknig
August 22nd, 2008, 09:12 AM
Just asking opinions here, what does everyone think is better for OOP and what is more effecient to do?

To have each class control itself with an onEnterFrame event inside the class? e.g.


class A extends MovieClip
{
public function A()
{
this.onEnterFrame = whatever;
}
}

class B extends MovieClip
{
public function B()
{
this.onEnterFrame = whatever;
}
}


Or to have a main class, instantiate the subclasses, and then run update methods in those instances through a for loop in the main class? e.g.



class A extends MovieClip
{
public function A()
{
}

public function update()
{
//do stuff
}
}

class B extends MovieClip
{
public function B()
{
}

public function update()
{
//do stuff
}
}

class Main extends MovieClip()
{
public function Main()
{
//instantiate instances of A and B, and add them to some arrays for looping through
this.onEnterFrame = this.enterFrameHandler;
}

private function enterFrameHandler()
{
//loop through arrays of instances and run update() in them
}
}

bluemagica
August 22nd, 2008, 10:12 AM
it kindof depends on your situation, however the second method, though will be a tiny bit less in speed, is much more forgiving on the processor than the first.

ArmoredSandwich
August 22nd, 2008, 01:46 PM
Definitely the second, even though I wouldn't use onEnterFrame at all :P, but mostly because you have SO much more control that way.

I believe there was a topic about this some time ago, let me see.

EDIT: Nahh, I can't seem to find. It was too long ago :(