Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

me.as

Name: me & my - [MX] self contained this
Author: senocular: www.senocular.com
Date: 1899-12-31T00:45:50.400
Documentation:
Object MY (and ME): 'this' substitute for objects
referencing themselves

myObject.my == myObject;
myObject.me == myObject;

(my and me are equivalent)

Seems dinky, I know, but can be valuable in with() blocks as the object youre using
with on has no 'this' - my, instead giving all objects a reference to themselves. Using
my, they can reference themselves in a with block as you would a 'this'.  The advantage
for variable assignement and passing the withed object as arguments which otherwise would
not allowed in with blocks for the withed object.

MY is more suited for something like variable assignment and ME is better for passing the
object as an argument (ME also relates to director users)

function traceNameOf(obj){
     trace(obj._name);
}
this.createEmptyMovieClip("myMovie",1);
with (myMovie){
	newVariable = 1;
	trace(myMovie.newVariable); // undefined
	my.newVariable = 1;
	trace(myMovie.newVariable); // 1
	traceNameOf(me); // myMovie
}

Example:
man = new Object();
hand = "timeline hand";
with (man){
	trace(hand); // timeline hand
	my.hand = "mans hand";
	trace(hand); // mans hand
}

1
2
Object.prototype.addProperty("my", function(){return this;},null);
Object.prototype.addProperty("me", function(){return this;},null);