Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsHow can I reference an array via an object?
Say I call BA[x] into a function "end(BA[x]);"
So to init the function "end" I would use:
function end(ob:object){
ob.Array.split(ob.Array.indexOf(ob), 1);
}
Obviously I cannot call the array through ob.Array. How can I call the array via the object?
thanks egg!
At 11/8/12 07:47 PM, stegrd wrote: How can I reference an array via an object?
Say I call BA[x] into a function "end(BA[x]);"
So to init the function "end" I would use:
function end(ob:object){
ob.Array.split(ob.Array.indexOf(ob), 1);
}
Obviously I cannot call the array through ob.Array. How can I call the array via the object?
If your object 'ob' has a public property called 'ar' (don't name them same as the class "Array") then you can call it like ob.ar[0] (gets value of first index in ar).
You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.
Thanks, but I mean if I can reference it without using the array's name because I have multiple arrays such as AB[] AA[] BA[] and so on.
thanks egg!
Why do you have a bunch of different arrays in the same scope? You need to explain what exactly you're trying to accomplish.
Oh, i'm trying to use the same function with multiple arrays. If it is not possible, ill just make more functions I suppose.
thanks egg!
At 11/9/12 12:51 AM, stegrd wrote: Oh, i'm trying to use the same function with multiple arrays. If it is not possible, ill just make more functions I suppose.
well, the point of OOP is re-usable code.
Why do you need to use full Objects? They're large and almost pointless.
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P
At 11/8/12 07:47 PM, stegrd wrote: How can I reference an array via an object?
Say I call BA[x] into a function "end(BA[x]);"
So to init the function "end" I would use:
function end(ob:object){
ob.Array.split(ob.Array.indexOf(ob), 1);
}
Obviously I cannot call the array through ob.Array. How can I call the array via the object?
Put a reference to the array inside the object when you create it.
var iceCream:Object = {name: "vanilla", containingArray: iceCreamArray};
iceCreamArray.push(iceCream);
function destroy(ob:Object):void {
ob.containingArray.splice(indexOf(ob), 1);
}
destroy(iceCream);
ob.containingArray.splice(indexOf(ob), 1);
Sorry, that should be
ob.containingArray.splice( ob.containingArray.indexOf(ob), 1);
At 11/9/12 12:51 AM, stegrd wrote: Oh, i'm trying to use the same function with multiple arrays. If it is not possible, ill just make more functions I suppose.
The question was what you want to accomplish, not to describe your code again.
What is that object?
What is in those arrays?
Why do you type your parameter to "Object"? (very bad)
At 11/9/12 03:19 AM, milchreis wrote:At 11/9/12 12:51 AM, stegrd wrote: Oh, i'm trying to use the same function with multiple arrays. If it is not possible, ill just make more functions I suppose.The question was what you want to accomplish, not to describe your code again.
What is that object?
What is in those arrays?
Why do you type your parameter to "Object"? (very bad)
DisplayObject, i've changed it though. thanks anyways.
I was just using arrays to hold sets of identical objects which would eventually enter a function for removeChild and array splice.
thanks egg!
At 11/9/12 05:47 AM, stegrd wrote: I was just using arrays to hold sets of identical objects which would eventually enter a function for removeChild and array splice.
So you got some sort of 'object / array' mess which you are unable to explain to us? I think it's time to get back to the drawing board and rethink your approach.
You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.