03-21-2011, 12:54 AM
|
#1
|
|
Deaths touch!!!
Join Date: Mar 2008
Posts: 775
|
retrieve Array name?
ok so basically i have a custom function for the array class. and within it i can refer to the aarray by using "this" however in a trace statement i want to be able to get the name of the array. does anyone know how to do this?
here is some code to help explain, if you didn't understand what was said above:
Code:
// i think getDefinitionByName() might be of some kind of help.
var myArray:Array = [1,2,3,4,5]
Array.prototype.functionName = function(){
trace("the name of the array this function is linked to is:");
// at the end of that i wish for it to say the arrays name.
}
myArray.functionName(); // so the array name it should give is myArray.
this has had me for hours...so if you guys could help that would be great.
|
|
|
03-21-2011, 01:58 AM
|
#2
|
|
Site Contributor
Join Date: Jun 2006
Posts: 3,160
|
What you are trying to do is not possible.
It's because of the way variable names are used to refer to objects. They are really just references (or "pointers") to the memory address that the object is located at, and there can be none, one, or any number of them. The object has no way of knowing internally how many references are pointing to it.
For example, you could do this:
var myOtherReference:Array = myArray;
Now both names point to the same array object and you can use them interchangeably. So which one is the "instance name" now??? Therefore, there is no such thing as one and only one name for an object. Get used to it.
Edit (update): What you do then, is stop relying on "names" so much in your programming, and get rid of the "one and only one name for an object" idea, which isn't true anyway. With an object (like your array), any reference that refers to it is a good reference. Within the object itself, you just refer to it as this.
Last edited by Mazoonist; 03-21-2011 at 02:04 AM.
|
|
|
03-21-2011, 04:01 AM
|
#3
|
|
Deaths touch!!!
Join Date: Mar 2008
Posts: 775
|
in the code i'm refering to it as this. but in the message i thought it might be cool to trace out the arrays name. ahh well, guess it doesn't matter i can find another way to write what i was going to write; simply would have been cooler to have it with the array name as all.
but if its not possible it doesn't matter i can write it differently to suite what i wanted.
thanks for the help!
|
|
|
03-21-2011, 04:25 AM
|
#4
|
|
Site Contributor
Join Date: Jun 2006
Posts: 3,160
|
Quote:
|
i thought it might be cool to trace out the arrays name
|
That's just it, the array does not have just one name, or even any name at all. Names are just references. You are going to have to get it out of your mind completely that objects have names. They don't.
Edit: Or put another way, any name pointing to an object (of which there can be many, not limited to just one) is just a temporary reference, for the purpose of calling methods and properties on the object.
Last edited by Mazoonist; 03-21-2011 at 04:28 AM.
|
|
|
03-21-2011, 09:59 AM
|
#5
|
|
Senior Member
Join Date: Mar 2009
Location: Sweden
Posts: 9,840
|
ActionScript Code:
trace(["Who", "am", "I?", "I", "am", "nobody."].join(" "));
__________________
Signature: I wrote a pair of articles about the timeline.
|
|
|
03-21-2011, 12:47 PM
|
#6
|
|
!Senior Member
Join Date: Jan 2010
Posts: 1,675
|
ActionScript Code:
var arr:Array = [1,2,3,4];
arr.fn = function ():void { trace(this,this.name); };
arr.name = "arr";
arr.fn();
var arr2:Array = arr;
arr2.name += ",arr2";
arr2.fn();
chill guys, just jokin'
|
|
|
03-21-2011, 01:15 PM
|
#7
|
|
dont Re Member
Join Date: May 2009
Location: Poland
Posts: 733
|
humbly and shy, wanna put that here(I've learned about Dictionary couple days ago)
ActionScript Code:
import flash.utils.Dictionary;
var arrDict:Dictionary = new Dictionary(true);
var arr1:Array = new Array(1,2,3,4);
arrDict[arr1] = {name:"arr1"};
var askingAboutArr:Object = arrDict[arr1];
trace(askingAboutArr.name);
trace(askingAboutArr.name.length)
Of course it is a joke category too.
Cheers.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 06:49 AM.
///
|
|