I'm playing around with some code for a future project and I need a little help. The file is set up with four squares. When you mouse over one it fades in and remains that way until you mouse out, then it fades out. I'm using tweens to acomplish this. It works fine until you go from one square to the next and then back to the previous square before the tween is over. If you go back to the previous square, which is currently fading out, it does this sort of hiccup thing where the square flashes and then fades out really quick and won't reappear until you mouse out and and mouse over again. Any help solving this issue would be greatly appreciate it. Thanks.
---------------------------------------------------------------------- ----------------------
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
stop();
var displayDetails:popUpInfo = new popUpInfo();
// Pop-up duration
var myTimer:Timer = new Timer(3000, 1);
// Counts time until pop-up removed from stage
var timePopUp:Timer = new Timer(300, 1);
// Pop-up active if true, inactive if false
var popupState:Boolean = false;
var objectArray:Array = [topLeft, topRight, bottomLeft, bottomRight];
for (var i:int = 0; i < objectArray.length; i++) {
objectArray[i].addEventListener(MouseEvent.MOUSE_OVER, fadeBlockIn);
objectArray[i].addEventListener(MouseEvent.MOUSE_OUT, fadeBlockOut);
objectArray[i].addEventListener(MouseEvent.CLICK, displayInfo);
}
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
timePopUp.addEventListener(TimerEvent.TIMER_COMPLETE, removePopUp);
topLeft.alpha = 0;
topRight.alpha = 0;
bottomLeft.alpha = 0;
bottomRight.alpha = 0;
// Fades current selection in
function fadeBlockIn(evt:MouseEvent):void {
var myTweenIn:Tween = new Tween(evt.target, "alpha", Strong.easeIn, 0, 1, .1, true);
}
// Fades current selection out when mout out
function fadeBlockOut(evt:MouseEvent):void {
var myTweenOut:Tween = new Tween(evt.target, "alpha", Strong.easeOut, 1, 0, 1, true);
}
// Adds pop up with information to stage
function displayInfo(evt:MouseEvent):void{
addChild(displayDetails);
var fadeInInfo:Tween = new Tween(displayDetails, "alpha", Strong.easeIn, 0, 1, .3, true);
displayDetails.x = evt.target.x + 62;
displayDetails.y = evt.target.y - 17;
switch(evt.target.name){
case "topLeft":
displayDetails.detailInfoCopy.text = "top left corner";
break;
case "topRight":
displayDetails.detailInfoCopy.text = "top right corner";
break;
case "bottomLeft":
displayDetails.detailInfoCopy.text = "bottom left corner";
break;
case "bottomRight":
displayDetails.detailInfoCopy.text = "bottom right corner";
break;
}
// Resets timer when new box clicked if timer is already running.
// Timer set to remove pop-up box automatically
if (popupState = false) {
myTimer.start();
popupState = true;
} else {
popupState = false;
myTimer.reset();
myTimer.start();
}
}
// Fades pop-up with information box out
function timerHandler(evt:TimerEvent):void{
var fadeOutInfo:Tween = new Tween(displayDetails, "alpha", Strong.easeOut, 1, 0, .3, true);
// Timer removes pop-up from stage at the same time alpha = 0
timePopUp.start();
}
// Removes pop-up from stage when timer calls function
function removePopUp(evt:TimerEvent):void{
removeChild(displayDetails);
popupState = false;
}
if your blocks are movieclips, you can use the following. (or, even better, use a third party tween class like tweenlite that let's you overwrite tweens.):
---------------------------------------------------------------------- ----------------------
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
stop();
var displayDetails:popUpInfo = new popUpInfo();
// Pop-up duration
var myTimer:Timer = new Timer(3000, 1);
// Counts time until pop-up removed from stage
var timePopUp:Timer = new Timer(300, 1);
// Pop-up active if true, inactive if false
var popupState:Boolean = false;
var objectArray:Array = [topLeft, topRight, bottomLeft, bottomRight];
for (var i:int = 0; i < objectArray.length; i++) {
objectArray[i].addEventListener(MouseEvent.MOUSE_OVER, fadeBlockIn);
objectArray[i].addEventListener(MouseEvent.MOUSE_OUT, fadeBlockOut);
objectArray[i].addEventListener(MouseEvent.CLICK, displayInfo);
}
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
timePopUp.addEventListener(TimerEvent.TIMER_COMPLETE, removePopUp);
topLeft.alpha = 0;
topRight.alpha = 0;
bottomLeft.alpha = 0;
bottomRight.alpha = 0;
// Fades current selection in
function fadeBlockIn(evt:MouseEvent):void {
if(MovieClip(evt.currentTarget).fadeOutTween){
MovieClip(evt.currentTarget).fadeOutTween.stop();
}
MovieClip(evt.currentTarget).fadeInTween = new Tween(evt.target, "alpha", Strong.easeIn, evt.currentTarget.alpha, 1, .1, true);
}
// Fades current selection out when mout out
function fadeBlockOut(evt:MouseEvent):void {
if( MovieClip(evt.currentTarget).fadeInTween){
MovieClip(evt.currentTarget).fadeInTween.stop();
}
MovieClip(evt.currentTarget).fadeOutTween = new Tween(evt.target, "alpha", Strong.easeOut, evt.currentTarget.alpha, 0, 1, true);
}
// Adds pop up with information to stage
function displayInfo(evt:MouseEvent):void{
addChild(displayDetails);
var fadeInInfo:Tween = new Tween(displayDetails, "alpha", Strong.easeIn, 0, 1, .3, true);
displayDetails.x = evt.target.x + 62;
displayDetails.y = evt.target.y - 17;
switch(evt.target.name){
case "topLeft":
displayDetails.detailInfoCopy.text = "top left corner";
break;
case "topRight":
displayDetails.detailInfoCopy.text = "top right corner";
break;
case "bottomLeft":
displayDetails.detailInfoCopy.text = "bottom left corner";
break;
case "bottomRight":
displayDetails.detailInfoCopy.text = "bottom right corner";
break;
}
// Resets timer when new box clicked if timer is already running.
// Timer set to remove pop-up box automatically
if (popupState = false) {
myTimer.start();
popupState = true;
} else {
popupState = false;
myTimer.reset();
myTimer.start();
}
}
// Fades pop-up with information box out
function timerHandler(evt:TimerEvent):void{
var fadeOutInfo:Tween = new Tween(displayDetails, "alpha", Strong.easeOut, 1, 0, .3, true);
// Timer removes pop-up from stage at the same time alpha = 0
timePopUp.start();
}
// Removes pop-up from stage when timer calls function
function removePopUp(evt:TimerEvent):void{
removeChild(displayDetails);
popupState = false;
}
North America
Europe, Middle East and Africa
Asia Pacific