Be a Supporter!

Need to reference array via object?

  • 320 Views
  • 10 Replies
New Topic Respond to this Topic
stegrd
stegrd
  • Member since: Nov. 5, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Need to reference array via object? 2012-11-08 19:47:33 Reply

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?


thanks egg!

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to Need to reference array via object? 2012-11-08 21:14:02 Reply

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.

stegrd
stegrd
  • Member since: Nov. 5, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Need to reference array via object? 2012-11-09 00:23:18 Reply

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!

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Need to reference array via object? 2012-11-09 00:44:34 Reply

Why do you have a bunch of different arrays in the same scope? You need to explain what exactly you're trying to accomplish.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
stegrd
stegrd
  • Member since: Nov. 5, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Need to reference array via object? 2012-11-09 00:51:34 Reply

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!

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Need to reference array via object? 2012-11-09 00:56:50 Reply

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

BBS Signature
ScrumTurd
ScrumTurd
  • Member since: Sep. 10, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Need to reference array via object? 2012-11-09 01:06:26 Reply

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

ScrumTurd
ScrumTurd
  • Member since: Sep. 10, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Need to reference array via object? 2012-11-09 01:48:15 Reply

ob.containingArray.splice(indexOf(ob), 1);

Sorry, that should be

ob.containingArray.splice( ob.containingArray.indexOf(ob), 1);

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Need to reference array via object? 2012-11-09 03:19:21 Reply

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)

stegrd
stegrd
  • Member since: Nov. 5, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Need to reference array via object? 2012-11-09 05:47:32 Reply

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!

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to Need to reference array via object? 2012-11-09 07:19:42 Reply

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.