Someone gifted MetalSlayer69 supporter status!
We need you on the team, too.
Support Newgrounds and get tons of perks for just $2.99!
Create a Free Account and then..
Become a Supporter!A couple changes/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME (and immediately remove the ENTER_FRAME listener so that it doesn't need to be called when nothing's changed).
The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case - so it'll work even with e.g. Sprite or Shape derived objects (although for the latter you'll have to create an EventDispatcher instance since Shape doesn't have one by itself).
The downside is that each of the downstream classes (e.g. asClass) will need to have code to dispatch the REARRANGE event, but I don't really see how that's too different from the current method, as you will anyways need to know when to update the depths.
A couple changes/suggestions/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME (and immediately remove the ENTER_FRAME listener so that it doesn't need to be called when nothing's changed).
The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case - so it'll work even with e.g. Sprite or Shape derived objects (although for the latter you'll have to create an EventDispatcher instance since Shape doesn't have one by itself).
The downside is that each of the downstream classes (e.g. asClass) will need to have code to dispatch the REARRANGE event, but I don't really see how that's too different from the current method, as you will anyways need to know when to update the depths.
A couple changes/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME (and immediately remove the ENTER_FRAME listener so that it doesn't need to be called when nothing's changed).
The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case.
The downside is that each of the downstream classes (e.g. asClass) will need to have code to dispatch the REARRANGE event, but I don't really see how that's too different from the current method, as you will anyways need to know when to update the depths.
A couple changes/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME (and immediately remove the ENTER_FRAME listener so that it doesn't need to be called when nothing's changed).
The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case - so it'll work even with e.g. Sprite or Shape derived objects (although for the latter you'll have to create an EventDispatcher instance since Shape doesn't have one by itself).
The downside is that each of the downstream classes (e.g. asClass) will need to have code to dispatch the REARRANGE event, but I don't really see how that's too different from the current method, as you will anyways need to know when to update the depths.
A couple changes/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME (and immediately remove the ENTER_FRAME listener so that it doesn't need to be called when nothing's changed). The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case.
The downside is that each of the downstream classes (e.g. asClass) will need to have code to dispatch the REARRANGE event, but I don't really see how that's too different from the current method, as you will anyways need to know when to update the depths.
A couple changes/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME (and immediately remove the ENTER_FRAME listener so that it doesn't need to be called when nothing's changed).
The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case.
The downside is that each of the downstream classes (e.g. asClass) will need to have code to dispatch the REARRANGE event, but I don't really see how that's too different from the current method, as you will anyways need to know when to update the depths.
A couple changes/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME. The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case.
A couple changes/questions I noticed...
var depth:int = Math.floor(obj.y);
Calling Math.floor() on something that'll anyways be stored as an int is probably unnecessary; since calling static methods is slow, best avoid it unless there's a good reason to.
I guess you're implementing this as a function that can be called by any movieclip that you want to be stacked by Y? That is, if you have 3 objects that need to be stacked by Y, then they should all have DepthY somewhere in the inheritance chain (e.g. X extends DepthY)?
If that's the case, it's probably much better to make the parent container manage its children rather than have the children manage themselves. This way, rather than calling updateDepths once per object in the container, it can be called just once -- by the parent container.
That's not to say that you can't have the child movieclips manage themselves -- it's possible to have your cake here and eat it too. By adding a custom Event listener (e.g. "REARRANGE" or something) to the parent container, you can have the child movieclips dispatch these events whenever they move, for example. Then, the parent container will call updateDepths in the next ENTER_FRAME (and immediately remove the ENTER_FRAME listener so that it doesn't need to be called when nothing's changed). The benefit of this method is that even if there are 200 objects in the parent container, you'll only call updateDepths once, because all the REARRANGE event would do is to tell the container to eventually call updateDepths. Furthermore, you'll be achieving the same outcome in a more modular manner - you won't be bound to inheriting from DepthY in this case.
The downside is that each of the downstream classes (e.g. asClass) will need to have code to dispatch the REARRANGE event, but I don't really see how that's too different from the current method, as you will anyways need to know when to update the depths.