# HOW do I control a cross fade with buttons?

**URL:** <https://forum.kirupa.com/t/how-do-i-control-a-cross-fade-with-buttons/282667>\
**Category:** flash\
**Created:** [February 24, 2009, 11:05pm UTC](https://forum.kirupa.com/t/how-do-i-control-a-cross-fade-with-buttons/282667 "2009-02-24T23:05:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CallClass](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@CallClass](https://forum.kirupa.com/u/CallClass)\
**Post date:** [February 24, 2009, 11:05pm UTC](https://forum.kirupa.com/t/how-do-i-control-a-cross-fade-with-buttons/282667/1 "2009-02-24T23:05:23Z")

</div>

Dear Readers

The AS3 script below is a cross-fade that is time-based with no user control. How do I keep the cross fade and control it with the “before” and “after” buttons? And with the API opening in its “before” state? And for users to be able to click and/or hover between the two. The link to what I’m trying to set up is:

[http://www.ksqdesign.com/signature/F...o/trantwo.html](http://www.ksqdesign.com/signature/F...o/trantwo.html)

The code is:

import fl.transitions.Tween;  
import fl.transitions.TweenEvent;  
import fl.transitions.easing.\*;  
var bg1Tween:Tween = new Tween (beforeD1, “alpha”, None.easeInOut, 0 , 1 , 1 , true );  
bg1Tween.stop();  
bg1Tween.addEventListener(TweenEvent.MOTION\_FINISH ,fadeOutbg);  
var bg2Tween:Tween = new Tween (beforeD1, “alpha”, None.easeInOut, 0 , 1 , 1 , true );

bg2Tween.stop();  
var bg3Tween:Tween = new Tween (afterD1, “alpha”, None.easeInOut, 0 , 1 , 1 , true);  
bg3Tween.stop();

beforeD1.nextTween = bg2Tween;  
beforeD1.nextTween = bg3Tween;  
afterD1.nextTween = bg1Tween;

setTimeout (bg1Tween.start, 1000);

function fadeOutbg(event:TweenEvent) {  
event.target.removeEventListener(TweenEvent.MOTION \_FINISH, fadeOutbg);  
event.target.addEventListener(TweenEvent.MOTION\_FI NISH, startNextbg);  
event.target.begin = 1;  
event.target.finish = 0;  
setTimeout (event.target.start, 6000);  
}  
function startNextbg(event:TweenEvent) {  
event.target.removeEventListener(TweenEvent.MOTION \_FINISH, startNextbg);  
event.target.obj.nextTween.addEventListener(TweenE vent.MOTION\_FINISH, fadeOutbg);  
event.target.obj.nextTween.begin = 0;  
event.target.obj.nextTween.finish = 1;  
setTimeout (event.target.obj.nextTween.start, 1000);  
}

Many thanks for your time and help.

CC
