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

 

senocular.com ActionScript Library

attachMember.as

Name: attachMember/_member - easily change a 'member' or the contents of an attached movieclip
Author: senocular: www.senocular.com
Date: 1899-12-31T00:52:05.300
Documentation:
MovieClip ATTACHMEMBER with _MEMBER property:
Allows creation of movieclips with _member properties which
specify what movieclip for the library is used to make up the
contents of this movieclip - similar to member properties of
sprites in Director.

myMovieClip.attachMember();
- basically like attachMovie except that the actual movieclip from id is attached in an empty
clip which makes up your actual attached movie.  The linker movie is set in the empty clip as
member_mc.  If _member is changed, that movieclip is replaced with the new movieclip of the
specified member.

Typically you wont have to worry about member_mc unless you have contents within it you need
to access, whether it be other movieclips or code.

myMovieClip._member;
- property specifying the linker id (or 'member') that makes up the contents of an attached
Member movieclip.  This can be tested and set.  Setting it will replace the member_mc with the
new movieclip as specified from the linker id assigned to _member.

Example:
// "circle" and "square" are linker IDs of 
// movieclips in the library
// first attach a clip normally using attachMember
this.attachMember("circle", "myClip", 1, {_x:150,_y:150});
// then mouse events are used to change the 'member' of the
// clip - effectively just reattaching the movieclip
// with that linker ID in the movieclip changing its
// contents to be that of the specified linker movieclip.
myClip.onMouseDown = function(){
	this._member = "square";
};
myClip.onMouseUp = function(){
	this._member = "circle";
};

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
MovieClip.prototype.attachMember = function(id,name,depth, init){
	var m = this.createEmptyMovieClip(name, depth);
	if (init){
		var p = init.__proto__;
		init.__proto__ = null;
		for (var i in init) m<i> = init<i>;
		init.__proto__ = p;
	}		
	m.attachMovie(id,"member_mc",0);
	m.$member = id;
	return m;
};
MovieClip.prototype.addProperty("_member",function(){
		return this.$member;
	},function(id){
		this.attachMovie(id,"member_mc",0);
		this.$member = id;
	}
);