import mx.utils.Delegate; class CustomMC extends MovieClip { public var depth : Number; private var currentScale : Number =100; private var fadeSpeed: Number; private var step : Number; private static var steps=10; private var popOutAfterIn = false; private var removeAfterPopOut = false; public function onComplete () {} // for loading jpg public function getPos () { // returns a vector with the coordinates of this clip var v:Vector = new Vector (this._x,this._y); return v; } public function scale (scale) { //currentScale = this._xscale; this._xscale = scale; this._yscale = scale; }; public function setPos (p) { this._x = p.x; this._y = p.y; } public function set3DPos (p,scale) { // automatically set right depth and scale var p2D = p.to2D(); this._x = p2D.x; this._y = p2D.y; this.set3DDepth(p); if (scale!=false) this.scale (2500/p.y); //trace ("depth="+this.getDepth()); //trace ("y="+p.y); //trace ("new depth : "+(5000-p.y)); } /* public function rotate (angle) { //rotate in radians this._rotation = CustomMath.degrees(angle); }; */ public function loaded () { // clip should be 10 bytes at least return (this.getBytesLoaded()> 10) && (this.getBytesTotal()!=0) && (this.getBytesLoaded()==this.getBytesTotal() ); }; public function stopEvents (eventtype) { // removes events in all movies in this clip for (var i in this) { if (typeof(this[i])=="movieclip") { this[i][eventtype] = null; } } } public function removeAttached () { // removes all attached movies for (var i in this) { //trace (typeof(this[i])); if (typeof(this[i])=="movieclip") { this[i].removeMovieClip(); } } } public function setColor (colour) { var c=new Color (this); c.setRGB(colour); } public function fadeIn (fadeSpeed) { this.fadeSpeed = fadeSpeed; this._alpha=fadeSpeed; this.onEnterFrame = function () { this._alpha += this.fadeSpeed; if (this._alpha>=100) { this.onEnterFrame=null; } } } public function fadeOut (fadeSpeed) { trace ("fade out!"); //this.destroy = destroy; this.fadeSpeed = fadeSpeed; this.onEnterFrame = function () { this._alpha -= this.fadeSpeed; if (this._alpha<=0) { this.onEnterFrame=null; //this.removeCustomMC(); } } } public function bringToFront () { this.swapDepths(this._parent.getNextHighestDepth()); } public function blink (freq, duration) { if (freq==null) freq=1; // jump to a frame after a specific number of frames has passed // reset //this.blinker.removeMovieClip(); this._visible = true; // apply new interval if (freq>0) { var blinker = this.createEmptyMovieClip("blinker",this.getNextHighestDepth()); blinker.duration = duration; blinker.currentFrame = 0; blinker.freq = freq; blinker.onEnterFrame=function () { this.currentFrame++; if (this.currentFrame % this.freq == 0) this._parent._visible = !(this._parent._visible); if (this.currentFrame>=this.duration && this.duration!=null) { //this.removeMovieClip(); } } } } public function set3DDepth (pos) { var newDepth = this.get3DDepth (pos); //trace (_name+" new depth="+this.getDepth() +" - y="+pos.y); this.swapDepths (newDepth); } public function get3DDepth (pos) { // // sets the depth, depending on the y-position of the object var maxDepth = 1000000; var maxLoops = 100; var y=pos.y; var z=pos.z; if (z<-500) z = -500; if (z>500) z = 500; var newDepth = Math.round(maxDepth-Math.round(y*10000)+500+Math.round(z*10)); var clipAtThisDepth = this._parent.getInstanceAtDepth(newDepth); _root.depthLoops=0; while (clipAtThisDepth!=this && clipAtThisDepth!=undefined && _root.depthLoops=0) { var perc = Tools.tilt(step/steps,0.1) scale(currentScale*perc); _visible = true; } else { this.onEnterFrame=null; if (removeAfterPopOut) { this.removeMovieClip (); //trace ("remove "+_name) } else { scale(currentScale); _visible=false; } } } } }