RE: [Flashcoders] getting the name of an object
Just give you objects a property named (name) and trace object.name. my thoughts b -Original Message- From: Sascha Balkau [mailto:[EMAIL PROTECTED] Sent: Monday, January 23, 2006 9:19 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] getting the name of an object Modifying a debug tool and thought there could be some way to trace out the name of an object that is being traced recursively instead of having just [Object] [object] before it. Not that this is necessary, it would be just a 'nice to have' option. Thanks for help and explanation all! -Sascha - Original Message - From: "Morten Barklund Shockwaved" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Monday, January 23, 2006 11:23 PM Subject: Re: [Flashcoders] getting the name of an object > Couldn't you rather explain, what you were trying to accomplish - then > maybe we could understand and help? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Looks useful! Thanks Julius I will try out this code later today! -Sascha - Original Message - From: "Julius - XK" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Tuesday, January 24, 2006 5:07 AM Subject: Re: [Flashcoders] getting the name of an object Is this what your looking for? It has it's limitations, would be nice if there was a myObj.toString() == "myObj".. Or something along those lines :) var myObj:Object = new Object; var s:String = ""; s = getMyObjectName(myObj); trace(s); this[s].anyName = "text"; trace(myObj.anyName); function getMyObjectName(obj):String { for (i in this) { if (this[i] == obj) return i;// Should it be ===? } } ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
For the reasons given by Danny et al, you could never have a myObj.getString() such as you describe... other than possibly for debugging purposes, I'm at a loss to work out why it'd be useful? Ian On 1/23/06, Julius - XK <[EMAIL PROTECTED]> wrote: > > > Is this what your looking for? It has it's limitations, would be nice if > there was a myObj.toString() == "myObj".. Or something > along those lines :) > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Is this what your looking for? It has it's limitations, would be nice if there was a myObj.toString() == "myObj".. Or something along those lines :) var myObj:Object = new Object; var s:String = ""; s = getMyObjectName(myObj); trace(s); this[s].anyName = "text"; trace(myObj.anyName); function getMyObjectName(obj):String { for (i in this) { if (this[i] == obj) return i;// Should it be ===? } } - Original Message - From: "Sascha Balkau" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Monday, January 23, 2006 12:19 PM Subject: Re: [Flashcoders] getting the name of an object Modifying a debug tool and thought there could be some way to trace out the name of an object that is being traced recursively instead of having just [Object] [object] before it. Not that this is necessary, it would be just a 'nice to have' option. Thanks for help and explanation all! -Sascha - Original Message - From: "Morten Barklund Shockwaved" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Monday, January 23, 2006 11:23 PM Subject: Re: [Flashcoders] getting the name of an object Couldn't you rather explain, what you were trying to accomplish - then maybe we could understand and help? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Hm. Good point, and something I should go away and test. :-) I had it in my head somewhere that Flash did a low-level crude equality check on objects with == - are they both the same type and do the properties match? But I may well have misremembered that as a feature of a different language - I do seem to be switching between different languages for different tasks a lot these days. :-) Cheers, Ian On 1/23/06, Andreas Weber <[EMAIL PROTECTED] > wrote: > > > shouldn't there be a === or !== in there somewhere to make > > sure you're talking about _exactly_ the same object rather > > than one which just has the same value..? > Good question... > In my understanding - i.e. please correct me if I'm wrong! - when > testing objects for equality the simple and the strict equality operator > are completely interchangeable. > > We are not comparing values, which can be of different types (and thus > provoke 'false positives' with the simple equality operator), but > references, which have a simple, 'binary' quality: either they do point > at the same place in memory or they don't. > And two objects - by definition? - always occupy two distinct locations > in memory, completely independent of wether they are of the same type > and contain the same values. > >trace({} == {});// output: false > > That's why I think that when testing objects for equality, the simple > and the strict oprator will always return the same result. > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Oh guys, this reminds me of var a:Object=new Object(); var b:Object=new Object(); a.b=b; b.a=a; trace(a.b.a.b.a.b.a.b.a until I die) On 1/23/06, Andreas Weber <[EMAIL PROTECTED]> wrote: > > > shouldn't there be a === or !== in there somewhere to make > > sure you're talking about _exactly_ the same object rather > > than one which just has the same value..? > > Good question... > In my understanding - i.e. please correct me if I'm wrong! - when > testing objects for equality the simple and the strict equality operator > are completely interchangeable. > > We are not comparing values, which can be of different types (and thus > provoke 'false positives' with the simple equality operator), but > references, which have a simple, 'binary' quality: either they do point > at the same place in memory or they don't. > And two objects - by definition? - always occupy two distinct locations > in memory, completely independent of wether they are of the same type > and contain the same values. > > trace({} == {});// output: false > > That's why I think that when testing objects for equality, the simple > and the strict oprator will always return the same result. > > -- > Andreas Weber > motiondraw.com > > > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Ian > Thomas > Sent: Montag, 23. Januar 2006 16:38 > To: Flashcoders mailing list > Subject: Re: [Flashcoders] getting the name of an object > > > Andreas, > Just sight-reading the code rather than testing it - shouldn't there > be a === or !== in there somewhere to make sure you're talking about > _exactly_ the same object rather than one which just has the same > value..? > > Cheers, >Ian > > On 1/23/06, Andreas Weber <[EMAIL PROTECTED]> wrote: > > > > If you have a weakness for kludgy solutions, try the 'getObjNames' > > function below. > > Otherwise: don't 'forget' the names of the objects: store the name in > the > > same object, as an additional property. > > > > > > // 'don't try this at home!' > > > > a = {someProp:'someValue'}; > > b = {someProp:'someOtherValue'}; > > c = a; > > > > arr = [a, b]; > > > > > > // later, when we have 'forgotten' the names of the objects > > > > for(var i=0, len=arr.length; i > trace(getObjNames(arr[i]) + ' - someProp: '+ > arr[i].someProp); > > > > // Output: c,a - someProp: someValue > > // b - someProp: someOtherValue > > > > } > > > > > > // kludgy, poorly tested and a waste of processor cycles function > > getObjNames(o:Object, timeline:MovieClip){ > > var names:Array; > > var o2 = arguments[1] ? arguments[1] : _level0; > > if(!names){names = []} > > for(var p in o2){ > > if(typeof(o2[p]) == 'object'){ > > if(o2[p] != o){ > > getObjName(o, o2[p]); > > }else{ > > names.push(p); > > } > > } > > } > > return names; > > } > > > > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] getting the name of an object
> shouldn't there be a === or !== in there somewhere to make > sure you're talking about _exactly_ the same object rather > than one which just has the same value..? Good question... In my understanding - i.e. please correct me if I'm wrong! - when testing objects for equality the simple and the strict equality operator are completely interchangeable. We are not comparing values, which can be of different types (and thus provoke 'false positives' with the simple equality operator), but references, which have a simple, 'binary' quality: either they do point at the same place in memory or they don't. And two objects - by definition? - always occupy two distinct locations in memory, completely independent of wether they are of the same type and contain the same values. trace({} == {});// output: false That's why I think that when testing objects for equality, the simple and the strict oprator will always return the same result. -- Andreas Weber motiondraw.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: Montag, 23. Januar 2006 16:38 To: Flashcoders mailing list Subject: Re: [Flashcoders] getting the name of an object Andreas, Just sight-reading the code rather than testing it - shouldn't there be a === or !== in there somewhere to make sure you're talking about _exactly_ the same object rather than one which just has the same value..? Cheers, Ian On 1/23/06, Andreas Weber <[EMAIL PROTECTED]> wrote: > > If you have a weakness for kludgy solutions, try the 'getObjNames' > function below. > Otherwise: don't 'forget' the names of the objects: store the name in the > same object, as an additional property. > > > // 'don't try this at home!' > > a = {someProp:'someValue'}; > b = {someProp:'someOtherValue'}; > c = a; > > arr = [a, b]; > > > // later, when we have 'forgotten' the names of the objects > > for(var i=0, len=arr.length; i trace(getObjNames(arr[i]) + ' - someProp: '+ arr[i].someProp); > > // Output: c,a - someProp: someValue > // b - someProp: someOtherValue > > } > > > // kludgy, poorly tested and a waste of processor cycles function > getObjNames(o:Object, timeline:MovieClip){ > var names:Array; > var o2 = arguments[1] ? arguments[1] : _level0; > if(!names){names = []} > for(var p in o2){ > if(typeof(o2[p]) == 'object'){ > if(o2[p] != o){ > getObjName(o, o2[p]); > }else{ > names.push(p); > } > } > } > return names; > } > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Modifying a debug tool and thought there could be some way to trace out the name of an object that is being traced recursively instead of having just [Object] [object] before it. Not that this is necessary, it would be just a 'nice to have' option. Thanks for help and explanation all! -Sascha - Original Message - From: "Morten Barklund Shockwaved" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Monday, January 23, 2006 11:23 PM Subject: Re: [Flashcoders] getting the name of an object Couldn't you rather explain, what you were trying to accomplish - then maybe we could understand and help? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Andreas, Just sight-reading the code rather than testing it - shouldn't there be a === or !== in there somewhere to make sure you're talking about _exactly_ the same object rather than one which just has the same value..? Cheers, Ian On 1/23/06, Andreas Weber <[EMAIL PROTECTED]> wrote: > > If you have a weakness for kludgy solutions, try the 'getObjNames' > function > below. > Otherwise: don't 'forget' the names of the objects: store the name in the > same object, as an additional property. > > > // 'don't try this at home!' > > a = {someProp:'someValue'}; > b = {someProp:'someOtherValue'}; > c = a; > > arr = [a, b]; > > > // later, when we have 'forgotten' the names of the objects > > for(var i=0, len=arr.length; i trace(getObjNames(arr[i]) + ' - someProp: '+ arr[i].someProp); > > // Output: c,a - someProp: someValue > // b - someProp: someOtherValue > > } > > > // kludgy, poorly tested and a waste of processor cycles > function getObjNames(o:Object, timeline:MovieClip){ > var names:Array; > var o2 = arguments[1] ? arguments[1] : _level0; > if(!names){names = []} > for(var p in o2){ > if(typeof(o2[p]) == 'object'){ > if(o2[p] != o){ > getObjName(o, o2[p]); > }else{ > names.push(p); > } > } > } > return names; > } > > hth > ---------- > Andreas Weber > motiondraw.com > > > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Sascha > Balkau > Sent: Monday, January 23, 2006 2:03 PM > To: flashcoders > Subject: [Flashcoders] getting the name of an object > > > hi, > > this might be obvious but how do I get the name of an object? If I got an > object named fooObj how can I get Flash to for example trace out the name > of > the object, so that it traces "fooObj"? I know this works with movieclips > but how about objects or arrays? > > Sascha > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] getting the name of an object
If you have a weakness for kludgy solutions, try the 'getObjNames' function below. Otherwise: don't 'forget' the names of the objects: store the name in the same object, as an additional property. // 'don't try this at home!' a = {someProp:'someValue'}; b = {someProp:'someOtherValue'}; c = a; arr = [a, b]; // later, when we have 'forgotten' the names of the objects for(var i=0, len=arr.length; imailto:[EMAIL PROTECTED] Behalf Of Sascha Balkau Sent: Monday, January 23, 2006 2:03 PM To: flashcoders Subject: [Flashcoders] getting the name of an object hi, this might be obvious but how do I get the name of an object? If I got an object named fooObj how can I get Flash to for example trace out the name of the object, so that it traces "fooObj"? I know this works with movieclips but how about objects or arrays? Sascha ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Sascha Balkau wrote: Ok but it there a way to get the name of the variable that is reffering to the object? First I thought eval() could be used for that but it seems not. There is no "one" variable holding the name of an object. If your idea is something along a trace-function: function trace(o:Object):String { // return name of object here } trace(foo_object); Then one could argue, that both "foo_object" and "o" would be proper names of the variable holding the object - as there is many references. Couldn't you rather explain, what you were trying to accomplish - then maybe we could understand and help? -- Morten Barklund - Information Architect - Shockwaved Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark Phone: +45 7027 2227 - Fax: +45 3369 1174 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
Ok but it there a way to get the name of the variable that is reffering to the object? First I thought eval() could be used for that but it seems not. -Sascha - Original Message - From: "Danny Kodicek" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Monday, January 23, 2006 10:43 PM Subject: Re: [Flashcoders] getting the name of an object hi, this might be obvious but how do I get the name of an object? If I got an object named fooObj how can I get Flash to for example trace out the name of the object, so that it traces "fooObj"? I know this works with movieclips but how about objects or arrays? Objects or arrays don't have a name. That is: you could have a variable fooObj referring to some object O, and you could set another variable barObj to refer to the same object. The object O is completely independent of the variables referring to it. For that matter, an object held in an array doesn't even have a variable name referring to it. So unless you set up some kind of convention of your own, the request doesn't really make much sense. Danny ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
That's right. "_name" is a property of a movieclip object which is set the time you create and instance of a movieclip. When creating a generic object, it doens't have a _name or name property, unless you give it one. So, you could do this: var fooObj:Object = new Object(); fooObj.name = "" // whatever But as Danny said, the variable that holds the object has absolutely nothing to do with the name of the object. That goes the same for movieclips. You can do: var mc:MovieClip = _root.createEmptyMovieClip("myClip", 100); var movie:MovieClip = _root.myClip; var clip:MovieClip = mc; All three variables refer to the same movieclip object. Which is the name of the movieclip? Is it "mc", "movie", "clip" or "myClip"? It's the last one, "myClip", because you set it when creating the instance in the first place. No matter which variable holds a reference of the movieclip object, it doesn't affect the name property of the movieclip. I hope this helps. Dimitrios - Original Message - From: "Danny Kodicek" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Monday, January 23, 2006 3:43 PM Subject: Re: [Flashcoders] getting the name of an object hi, this might be obvious but how do I get the name of an object? If I got an object named fooObj how can I get Flash to for example trace out the name of the object, so that it traces "fooObj"? I know this works with movieclips but how about objects or arrays? Objects or arrays don't have a name. That is: you could have a variable fooObj referring to some object O, and you could set another variable barObj to refer to the same object. The object O is completely independent of the variables referring to it. For that matter, an object held in an array doesn't even have a variable name referring to it. So unless you set up some kind of convention of your own, the request doesn't really make much sense. Danny ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] getting the name of an object
hi, this might be obvious but how do I get the name of an object? If I got an object named fooObj how can I get Flash to for example trace out the name of the object, so that it traces "fooObj"? I know this works with movieclips but how about objects or arrays? Objects or arrays don't have a name. That is: you could have a variable fooObj referring to some object O, and you could set another variable barObj to refer to the same object. The object O is completely independent of the variables referring to it. For that matter, an object held in an array doesn't even have a variable name referring to it. So unless you set up some kind of convention of your own, the request doesn't really make much sense. Danny ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] getting the name of an object
fooObj._name Ade -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Sascha Balkau Sent: 23 January 2006 13:03 To: flashcoders Subject: [Flashcoders] getting the name of an object hi, this might be obvious but how do I get the name of an object? If I got an object named fooObj how can I get Flash to for example trace out the name of the object, so that it traces "fooObj"? I know this works with movieclips but how about objects or arrays? Sascha ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] getting the name of an object
hi, this might be obvious but how do I get the name of an object? If I got an object named fooObj how can I get Flash to for example trace out the name of the object, so that it traces "fooObj"? I know this works with movieclips but how about objects or arrays? Sascha ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders