|
-
solved! now, how to decently extend a class?
Hi, I solved it this way:
obj = new _objectClassArray[range(0, _objectClassArray.length - 1)];
simple 
I wonder now how could I extend the class ObjectPool
Cause I've just copied the whole code into a new .as file I called "MultipleObjectPool" and changed very little stuff on it.
But I know that's definitely not good practice.
So, these are the changes I've made in the "MultipleObjectPool" class:
1st - I added the "_objectClassArray" instance variable (not sure if it's called this way) , and removed the "_objectClass" instance variable since I didn't need it anymore.
2nd - The constructor changed:
Code:
public function ObjectPool(objectClass:Class, max:uint) {
_objectClass = objectClass;
becomes
Code:
public function ObjectPool(objectClassArray:Array, max:uint) {
_objectClassArray = objectClassArray;
3rd - in function request():
Code:
obj = new _objectClass();
becomes
Code:
obj = new _objectClassArray[range(0, _objectClassArray.length - 1)];
I'm not good enough in OOP to know how to do this... so please help! Then I can share it with you! 
Thanks!
-
hey, thanks for answering,
The objects in the array ware actually Classes.
i 'm still don't know why this didn't work:
Code:
var objClass:Class = _objectClassArray[range(0, _objectClassArray.length)] as Class;
obj = new objClass();
but the important thing is that this works:
Code:
obj = new _objectClassArray[range(0, _objectClassArray.length - 1)];
please read my previous post!
thanks!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|