Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-21-2011, 12:54 AM   #1
xdeath
Deaths touch!!!
 
xdeath's Avatar
 
Join Date: Mar 2008
Posts: 775
Default 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.
xdeath is offline   Reply With Quote
Old 03-21-2011, 01:58 AM   #2
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

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.
__________________
My Tutorials * My Website

Last edited by Mazoonist; 03-21-2011 at 02:04 AM.
Mazoonist is offline   Reply With Quote
Old 03-21-2011, 04:01 AM   #3
xdeath
Deaths touch!!!
 
xdeath's Avatar
 
Join Date: Mar 2008
Posts: 775
Default

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!
xdeath is offline   Reply With Quote
Old 03-21-2011, 04:25 AM   #4
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

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.
__________________
My Tutorials * My Website

Last edited by Mazoonist; 03-21-2011 at 04:28 AM.
Mazoonist is offline   Reply With Quote
Old 03-21-2011, 09:59 AM   #5
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,683
Send a message via Skype™ to henke37
Default

ActionScript Code:
trace(["Who", "am", "I?", "I", "am", "nobody."].join(" "));
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is online now   Reply With Quote
Old 03-21-2011, 12:47 PM   #6
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

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'
sparX is offline   Reply With Quote
Old 03-21-2011, 01:15 PM   #7
northmantif
dont Re Member
 
Join Date: May 2009
Location: Poland
Posts: 737
Default

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.
northmantif is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:38 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.