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

 

senocular.com ActionScript Library

FreeRangeMovieClip.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
FreeRangeMovieClip = function(id, mc){
	this.id = id;
	if (mc){
		this._mc = mc;
		this._mc.FRcontroller = this;
	}else this._mc = null;
}
FreeRangeMovieClip.prototype.getAbsoluteRotation = function(target){
	if (!target) target = this._mc;
	var r = target._rotation;
	while(target = target._parent) r += target._rotation
	return r;
}
FreeRangeMovieClip.prototype.getAbsoluteScale = function(target){ // assumes uniform
	if (!target) target = this._mc;
	var s = target._xscale/100;
	while(target = target._parent) s *= target._xscale/100;
	return s;
}
FreeRangeMovieClip.prototype.copyPropertiesFrom = function(target){
	var bak = target.__proto__; target.__proto__ = null;
	for (var p in target) if (target[p]._parent != target) this._mc[p] = target[p];
	target.__proto__ = bak;
}
FreeRangeMovieClip.prototype.copyVisualsFrom = function(target, apply_trans){
	var p = (apply_trans) ? arguments.callee.props : arguments.callee.props.slice(0,2);
	for (var i=0; i<p.length; i++) this._mc[p<i>] = target[p<i>];
}
FreeRangeMovieClip.prototype.copyVisualsFrom.props = ["_alpha","_visible","_rotation","_xscale","_yscale","_x","_y"];
FreeRangeMovieClip.prototype.attachMovie = function(target, name, depth, initObject){
	if (this._mc) this.removeMovieClip();
	this._mc = target.attachMovie(this.id, name, depth, initObject);
	this._mc.FRcontroller = this;
	return this._mc;
}
FreeRangeMovieClip.prototype.moveToMovieClip = function(target, depth, apply_trans, is_playing){
	if (!this._mc || this._mc._parent == target) return(0);
	if (depth == undefined) depth = this._mc.getDepth();
	var old = this._mc; this._mc = null;
	this.attachMovie(target, old._name, depth);
	this.copyPropertiesFrom(old);
	if (apply_trans) this.copyVisualsFrom(old, apply_trans);
	else {
		var loc = {x:old._x, y:old._y};
		old._parent.localToGlobal(loc);
		var abs_rotation = this.getAbsoluteRotation(old);
		var abs_scale = this.getAbsoluteScale(old);
		target.globalToLocal(loc);
		this._mc._x = loc.x; this._mc._y = loc.y;
		this._mc._rotation = abs_rotation - this.getAbsoluteRotation(target);
		this._mc._yscale = this._mc._xscale = abs_scale * 100/this.getAbsoluteScale(target);
		this.copyVisualsFrom(old, apply_trans);
	}
	if (is_playing) this._mc.gotoAndPlay(old._currentframe);
	else this._mc.gotoAndStop(old._currentframe);
	old.swapDepths(99999);
	old.removeMovieClip();
	return this._mc;
}
FreeRangeMovieClip.prototype.removeMovieClip = function(){
	this._mc.swapDepths(99999);
	this._mc.removeMovieClip();
	this._mc = null;
}
FreeRangeMovieClip.prototype.getValue = function(){
	return this._mc;
}
FreeRangeMovieClip.prototype.toString = function(){
	return this._mc._target;
}