/*---------------- FILE HEADER --------------------------------------- This file is part of Geoide. Copyright (C) 2005-2006 by: IDgis B.V. http://www.idgis.nl This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: Herman Assink IDgis bv P.O. Box 15 7450 AA Holten The Netherlands E-Mail: herman.assink@idgis.nl * @version 1.4.0 * @author IDgis team * ------------------------------------------------------------------------*/ class nl.idgis.giclient.framework.GeoideTip extends MovieClip { private var displayText : String = "nl.idgis.giclient.framework.GeoideTip"; //private var targetInstance; private var activeState : Boolean = true; private var handCursor : Boolean = false; private var useFade : Boolean; private var fadeInTime : Number = 300; private var fadeOutTime : Number = 500; private var displayDelay : Number = 300; private var displayShadow : Boolean; private var yOffset : Number = 20; private var xOffset : Number = 0; private var faceColor : Number; private var borderColor : Number; //private var targetOnRollOver : Function; //private var targetOnRollOut : Function; //private var targetOnReleaseOutside : Function; private var intervalID = undefined; private var start; private var fakeAlpha; private var fadePerSecond; private var isActive : Boolean = false; function GeoideTip() { // Setup the arrays to hold all of the skin information // As there is only one tooltip (which always get's modified) // a new skin system was developed that is different to the original skin system _root.toolTip_mc.styleList = new Array(); _root.toolTip_mc.originalStyles = new Array(); if (_root.toolTip_mc == undefined) { // create movie at a depth of 50000 _root.createEmptyMovieClip("toolTip_mc", 50000); _root.toolTip_mc.useHandCursor = false; // Attach all of the skins _root.toolTip_mc.attachMovie("ftt_shadow_mc", "shadow_mc0", 1, {controller:_root.toolTip_mc}); _root.toolTip_mc.attachMovie("ftt_shadow_mc", "shadow_mc1", 2, {controller:_root.toolTip_mc}); _root.toolTip_mc.attachMovie("ftt_shadow_mc", "shadow_mc2", 3, {controller:_root.toolTip_mc}); _root.toolTip_mc.attachMovie("ftt_shadow_mc", "shadow_mc3", 4, {controller:_root.toolTip_mc}); _root.toolTip_mc.attachMovie("ftt_border_mc", "border_mc", 5, {controller:_root.toolTip_mc}); _root.toolTip_mc.attachMovie("ftt_face_mc", "face_mc", 6, {controller:_root.toolTip_mc}); _root.toolTip_mc.faceC = new Color(_root.toolTip_mc.face_mc); _root.toolTip_mc.borderC = new Color(_root.toolTip_mc.border_mc); } // Setup mouse hooks //this.targetOnRollOver = this.targetInstance.onRollOver; //this.targetOnRollOut = this.targetInstance.onRollOut; //this.targetOnReleaseOutside = this.targetInstance.onReleaseOutside; // Reassign event handlers from target clip to use our handler //this.targetInstance.onRollOver = function() { // Call our tooltip_mc, after the user-defined delay elapses. //if(this.toolTip_mc.activeState) this.toolTip_mc.intervalID = setInterval(this.toolTip_mc, "displayToolTip", this.toolTip_mc.displayDelay); //this.toolTip_mc.targetOnRollOver.call(this); //} //this.targetInstance.onRollOut = function() { //this.toolTip_mc.isActive = false; //this.toolTip_mc.targetOnRollOut.call(this); // Call our removeToolTip. We need to use "call" because when this event // handler gets invoked, this == targetInstance, but our // displayToolTip assumes this == toolTip_mc. //this.toolTip_mc.removeToolTip.call(this.toolTip_mc); //} //this.targetInstance.onReleaseOutside = function() { //this.toolTip_mc.targetOnReleaseOutside.call(this); // Call our removeToolTip. We need to use "call" because when this event // handler gets invoked, this == targetInstance, but our // displayToolTip assumes this == toolTip_mc. //this.toolTip_mc.removeToolTip.call(this.toolTip_mc); //} // Set up watches on onRollOver and onRollOut in case user overrides //this.targetInstance.watch("onRollOver", this.ttROverReassign, this); //this.targetInstance.watch("onRollOut", this.ttROutReassign, this); //this.targetInstance.watch("onReleaseOutside", this.ttROutsideReassign, this); // Record pointer back to us in the targetInstance so we can scope events properly //this.targetInstance.toolTip_mc = this; // Set up the hand cursor property //this.targetInstance.useHandCursor = this.handCursor; // Initially hide the shadow - as we do each time the tooltip is faded out this.hideShadow(); // Make the tooltip invisible _root.toolTip_mc._visible = false; // Setup a hook to register skin elements // Otherwise they'd refer to _root.toolTip_mc //_root.toolTip_mc.class = this; _root.toolTip_mc.prototype = this; } /*function onMouseMove() { if(this.isActive) { // Prepare to move tool tip into position var mx2 = _root._xmouse + this.xOffset; var my = _root._ymouse + this.yOffset; // Reposition the tooltip if it runs off the stage if (mx2 + _root.toolTip_mc._width > Stage.width) { mx2 = Stage.width - _root.toolTip_mc._width; } if (my + _root.toolTip_mc._height > Stage.height) { my = Stage.height - _root.toolTip_mc._height - 15; } // Move the tool tip into position _root.toolTip_mc._x = mx2; _root.toolTip_mc._y = my; //_root.toolTip_mc._x = _root._xmouse + this.xOffset; //_root.toolTip_mc._y = _root._ymouse + this.yOffset; } }*/ function hideShadow(Void) : Void { // Hide all of the shadows from sight, jsut in-case the next tooltip doesn't use a shadow for (var i = 0; i < 4; i++) { var mc = _root.toolTip_mc["shadow_mc"+i]; mc._alpha = 0; mc._height = 1; mc._width = 1; mc._x = 0; mc._y = 0; } } // This function is triggered if the user reassigns onRollOver. // We need to make sure our onMouseMove is persistant function ttRMoveReassign(prop, oldVal, newVal, thisVal) { // Setup mouse hook thisVal.targetOnMouseMove = newVal; // Reassign event handlers from target clip to use our handler return (thisVal.onMouseMove); } // This function is triggered if the user reassigns onRollOver. // We need to make sure our onRollOver is persistant //function ttROverReassign(prop, oldVal, newVal, thisVal) { // Setup mouse hook //thisVal.targetOnRollOver = newVal; // Reassign event handlers from target clip to use our handler //return (thisVal.onRollOver); //} // This function is triggered if the user reassigns onRollOut. //function ttROutReassign(prop, oldVal, newVal, thisVal) { // Setup mouse hooks //thisVal.targetOnRollOut = newVal; // Reassign event handlers from target clip to use our handler //return (thisVal.onRollOut); //} // This function is triggered if the user reassigns onReleaseOutside. //function ttROutsideReassign (prop, oldVal, newVal, thisVal) { // Setup mouse hooks //thisVal.targetOnReleaseOutside = newVal; // Reassign event handlers from target clip to use our handler //return (thisVal.onReleaseOutside); //} // function: remove a tool tip function removeToolTip(Void) : Void { // If the delay hasn't produced tool tip yet, remove the tool tip since // the user has left the movie clip. We set intervalID to undefined in // case the system reuses intervalID's. if (this.intervalID != undefined) { clearInterval(this.intervalID); this.intervalID = undefined; } // Are we fading? if (this.useFade != true || this.fadeOutTime == 0) { _root.toolTip_mc._alpha = 0; _root.toolTip_mc._visible = false; } // call the fadeOut function to remove the movie clip if (this.useFade == true && this.fadeOutTime != 0) { // Start the timer _root.toolTip_mc.start = getTimer(); _root.toolTip_mc.fakeAlpha = _root.toolTip_mc._alpha; _root.toolTip_mc.fadePerSecond = 100/this.fadeOutTime; // Set the onEnterFrame event to the function which will fade out the tooltip _root.toolTip_mc.onEnterFrame = this.fadeOut; } } // Method: display the tool tip function displayToolTip(Void) : Void { this.isActive = true; // Clear the timer clearInterval(this.intervalID); this.intervalID = undefined; // Re-attach the LabelSymbol // It is easier just to re-attach each time rather than working out if we need to change properites if(_root.toolTip_mc.tipText_mc != undefined) _root.toolTip_mc.tipText_mc.removeMovieClip(); _root.toolTip_mc.attachMovie("Label", "tipText_mc", 7); _root.toolTip_mc.tipText_mc.autoSize = "left"; // Set the text _root.toolTip_mc.tipText_mc.text = this.displayText; _root.toolTip_mc.tipText_mc._width = 1; _root.toolTip_mc.tipText_mc.redraw(); // Setup the height for the skin // Make sure we setup the right size, for the right mode var layoutHeight = _root.toolTip_mc.tipText_mc.height + 2; // Setup the width of the skin var layoutWidth = _root.toolTip_mc.tipText_mc.width + 4; // Apply the skin and set the sizes _root.toolTip_mc.border_mc._width = layoutWidth; _root.toolTip_mc.border_mc._height = layoutHeight; _root.toolTip_mc.face_mc._width = layoutWidth-2; _root.toolTip_mc.face_mc._height = layoutHeight-2; _root.toolTip_mc.face_mc._x = 1; _root.toolTip_mc.face_mc._y = 1; _root.toolTip_mc.tipText_mc._x = 2; // Prepare to move tool tip into position var mx2 = _root._xmouse + this.xOffset; var my = _root._ymouse + this.yOffset; // Reposition the tooltip if it runs off the stage if (mx2 + _root.toolTip_mc._width > Stage.width) { mx2 = Stage.width - _root.toolTip_mc._width; } if (my + _root.toolTip_mc._height > Stage.height) { my = Stage.height - _root.toolTip_mc._height - 15; } // Move the tool tip into position _root.toolTip_mc._x = mx2; _root.toolTip_mc._y = my; // Check to see if a shadow is required if (this.displayShadow) { // Re-size the shadow mc's for (var i = 0; i < 4; i++) { var mc = _root.toolTip_mc["shadow_mc"+i]; mc._alpha = 25-(i*2); mc._height = layoutHeight; mc._width = layoutWidth; mc._x = i; mc._y = i; } } else { // don't display the shadow, make sure there resize to 1 x 1, so we can see them this.hideShadow(); } //Set colors _root.toolTip_mc.faceC.setRGB(this.faceColor); _root.toolTip_mc.borderC.setRGB(this.borderColor); // Make the tool tip visible _root.toolTip_mc._visible = true; // Are we using a fade? // _alpha should be 0 if we are (to fade it in) // and 100 if we aren't _root.toolTip_mc._alpha = (this.useFade == true && this.fadeInTime != 0) ? 0 : 100; // Start the clip fading in if needed // Otherwise make it visible straight away if (this.useFade == true && this.fadeInTime != 0) { // Get the timer and create the fake alpha // We use the fakeAlpha because you when you directly manipulate the _alpha property, the fade wont work as needed _root.toolTip_mc.start = getTimer(); _root.toolTip_mc.fakeAlpha = 0; _root.toolTip_mc.fadePerSecond = 100/this.fadeInTime; // Fade the clip in _root.toolTip_mc.onEnterFrame = this.fadeIn; } else { // Set onEnterFrame to undefined just incase it still exists from the fadeOut // This happens when you move from tooltip to tooltip really quickly _root.toolTip_mc.onEnterFrame = undefined; _root.toolTip_mc._visible = true; } } function fadeOut(Void) : Void { // Fade the tooltip out over time (in milliseconds) var previous = this.start; this.start = getTimer(); var elapsed = getTimer() - previous; var moveAmount = this.fadePerSecond * elapsed; this.fakeAlpha -= moveAmount; this._alpha = this.fakeAlpha; // Are we finished? if (this._alpha < 0) { // Remove this function from being called this.onEnterFrame = undefined; // hide the shadows this.hideShadow(); // hide the tool tip _root.toolTip_mc._visible = false; _root.toolTip_mc._alpha = 0; } if(this.isActive) displayToolTip(); } function fadeIn(Void) : Void { // Fade the clip in over the time specified (in milliseconds) // we use a fakeAlpha because if you apply floating point values // directly to the _alpha properties of a movie clip - things don't work out as expected var previous = this.start; this.start = getTimer(); var elapsed = getTimer() - previous; var moveAmount = this.fadePerSecond * elapsed; this.fakeAlpha += moveAmount; this._alpha = this.fakeAlpha; // Are we finish fading in? if (this._alpha > 100) { this._alpha = 100; this.onEnterFrame = undefined; } } //function removeMovieClip() { //if(this.isActive) //removeToolTip(); //this.targetInstance.unwatch("onRollOver"); //this.targetInstance.unwatch("onRollOut"); //this.targetInstance.unwatch("onReleaseOutside"); //this.targetInstance.onRollOver = this.targetOnRollOver; //this.targetInstance.onRollOut = this.targetOnRollOut; //this.targetInstance.onReleaseOutside = this.targetOnReleaseOutside; //super.removeMovieClip(); //} }