Tweening Issue
i'm playing around code future project , need little help. file set 4 squares. when mouse on 1 fades in , remains way until mouse out, fades out. i'm using tweens acomplish this. works fine until go 1 square next , previous square before tween over. if go previous square, fading out, sort of hiccup thing square flashes , fades out quick , won't reappear until mouse out , and mouse on again. solving issue 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 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; < 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 information 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 running.
// timer set remove pop-up box automatically
if (popupstate = false) {
mytimer.start();
popupstate = true;
} else {
popupstate = false;
mytimer.reset();
mytimer.start();
}
}
// fades pop-up 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 stage @ same time alpha = 0
timepopup.start();
}
// removes pop-up stage when timer calls function
function removepopup(evt:timerevent):void{
removechild(displaydetails);
popupstate = false;
}
if blocks movieclips, can use following. (or, better, use third party tween class tweenlite let's 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 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; < 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 information 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 running.
// timer set remove pop-up box automatically
if (popupstate = false) {
mytimer.start();
popupstate = true;
} else {
popupstate = false;
mytimer.reset();
mytimer.start();
}
}
// fades pop-up 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 stage @ same time alpha = 0
timepopup.start();
}
// removes pop-up stage when timer calls function
function removepopup(evt:timerevent):void{
removechild(displaydetails);
popupstate = false;
}
More discussions in ActionScript 3
adobe
Comments
Post a Comment