Highlight the button when the slideshow switches slides
hi all..
i have slideshow works forum.. 3 externally loaded swfs rotate fade in/outf effect on own per button click. add having the buttons change appearance (tint or anything) - show slide user seeing. i'm new , appreciate point me in direction of should place function. ahead of time - here's code:
// attach music
var req:urlrequest = new urlrequest("squeeak3.mp3");
var sound:sound = new sound();
var controller:soundchannel = new soundchannel();
var b:boolean;
if(!b) {
b=true;
function soundloaded(event:event):void
{
controller = sound.play(0,1000);
play_btn.addeventlistener(mouseevent.click, playsound);
stop_btn.addeventlistener(mouseevent.click, stopsound);
}
function playsound(event:mouseevent):void
{
soundmixer.stopall();
controller = sound.play(0,1000);
}
function stopsound(event:mouseevent):void
{
controller.stop();
soundmixer.stopall();
}
sound.addeventlistener(event.complete, soundloaded);
sound.load(req);
}
//import classes easier use
import fl.transitions.tween;
import fl.transitions.tweenevent;
import fl.transitions.easing.*;
//timer
var tl:movieclip = this;
var slideduration:uint = 8000;// or use whatever
var slidetimer:timer=new timer(slideduration,0);
slidetimer.addeventlistener(timerevent.timer,autoadvancef);
var previousbtn:simplebutton;
var btna:array = [one_btn,two_btn,three_btn];
function autoadvancef(e:timerevent):void {
nextbuttonf(previousbtn).dispatchevent(new mouseevent(mouseevent.click));
}
function nextbuttonf(btn:simplebutton):simplebutton {// use class type of buttons
(var i:uint=0; i<btna.length; i++) {
if (btna[i]==btn) {
return btna[(i+1)%btna.length];
}
}
return null;
}
//load external swf main
var xpos:number = 0;
var ypos:number = 0;
var loadera:array = [];
//btns universal function (whenver button clicked, loader removed
function btnclick(event:mouseevent):void {
slidetimer.reset();
slidetimer.start();
previousbtn = simplebutton(event.currenttarget);
var loader:loader = new loader();
loadera.push(loader);
var newswfrequest:urlrequest = new urlrequest("swfs/" + event.target.name + ".swf");
loader.contentloaderinfo.addeventlistener(event.complete,loadcomplete );
loader.load(newswfrequest);
loader.x = xpos;
loader.y = ypos;
loader.alpha = 0;
addchildat(loader,0);
}
var tween:tween;
function loadcomplete(e:event):void {
(var i:int=loadera.length-2; i>=0; i--) {
tl["tween_"+i] = new tween(loadera[i], "alpha", none.easein, loadera[i].alpha, 0, 1, true);
tl["tween_"+i].addeventlistener(tweenevent.motion_finish,onmotionfinish);
//
}
e.target.loader.contentloaderinfo.removeeventlistener(event.complete, loadcomplete);
tween = new tween(e.target.loader, "alpha", none.easein, 0, 1, 1, true);
}
function onmotionfinish(e:tweenevent) {
loader(e.target.obj).unload();
removechild(e.target.obj);
loadera.splice(loaderaindex(loader(e.target.obj)),1);
e.target.obj = null;
}
function loaderaindex(loader:loader):int{
for(var i:int=0;i<loadera.length;i++){
if(loadera[i]==loader){
return i;
}
}
return -1;
}
/// button listerners
one_btn.addeventlistener(mouseevent.click,btnclick);
two_btn.addeventlistener(mouseevent.click,btnclick);
three_btn.addeventlistener(mouseevent.click,btnclick);
btna[0].dispatchevent(new mouseevent(mouseevent.click));
use:
var lastclickedbutton:movieclip (or simplebutton or sprite);
// attach music
var req:urlrequest = new urlrequest("squeeak3.mp3");
var sound:sound = new sound();
var controller:soundchannel = new soundchannel();
var b:boolean;
if(!b) {
b=true;
function soundloaded(event:event):void
{
controller = sound.play(0,1000);
play_btn.addeventlistener(mouseevent.click, playsound);
stop_btn.addeventlistener(mouseevent.click, stopsound);
}
function playsound(event:mouseevent):void
{
soundmixer.stopall();
controller = sound.play(0,1000);
}
function stopsound(event:mouseevent):void
{
controller.stop();
soundmixer.stopall();
}
sound.addeventlistener(event.complete, soundloaded);
sound.load(req);
}
//import classes easier use
import fl.transitions.tween;
import fl.transitions.tweenevent;
import fl.transitions.easing.*;
//timer
var tl:movieclip = this;
var slideduration:uint = 8000;// or use whatever
var slidetimer:timer=new timer(slideduration,0);
slidetimer.addeventlistener(timerevent.timer,autoadvancef);
var previousbtn:simplebutton;
var btna:array = [one_btn,two_btn,three_btn];
function autoadvancef(e:timerevent):void {
nextbuttonf(previousbtn).dispatchevent(new mouseevent(mouseevent.click));
}
function nextbuttonf(btn:simplebutton):simplebutton {// use class type of buttons
(var i:uint=0; i<btna.length; i++) {
if (btna[i]==btn) {
return btna[(i+1)%btna.length];
}
}
return null;
}
//load external swf main
var xpos:number = 0;
var ypos:number = 0;
var loadera:array = [];
//btns universal function (whenver button clicked, loader removed
function btnclick(event:mouseevent):void {
if(lastclickedbtn!=null){
// lastclickedbtn - undo highlight
}
lastclickedbtn=event.currenttarget;
// event.currenttarget = hightlight
slidetimer.reset();
slidetimer.start();
previousbtn = simplebutton(event.currenttarget);
var loader:loader = new loader();
loadera.push(loader);
var newswfrequest:urlrequest = new urlrequest("swfs/" + event.target.name + ".swf");
loader.contentloaderinfo.addeventlistener(event.complete,loadcomplete );
loader.load(newswfrequest);
loader.x = xpos;
loader.y = ypos;
loader.alpha = 0;
addchildat(loader,0);
}
var tween:tween;
function loadcomplete(e:event):void {
(var i:int=loadera.length-2; i>=0; i--) {
tl["tween_"+i] = new tween(loadera[i], "alpha", none.easein, loadera[i].alpha, 0, 1, true);
tl["tween_"+i].addeventlistener(tweenevent.motion_finish,onmotionfini sh);
//
}
e.target.loader.contentloaderinfo.removeeventlistener(event.complete, loadcomplete);
tween = new tween(e.target.loader, "alpha", none.easein, 0, 1, 1, true);
}
function onmotionfinish(e:tweenevent) {
loader(e.target.obj).unload();
removechild(e.target.obj);
loadera.splice(loaderaindex(loader(e.target.obj)),1);
e.target.obj = null;
}
function loaderaindex(loader:loader):int{
for(var i:int=0;i<loadera.length;i++){
if(loadera[i]==loader){
return i;
}
}
return -1;
}
/// button listerners
one_btn.addeventlistener(mouseevent.click,btnclick);
two_btn.addeventlistener(mouseevent.click,btnclick);
three_btn.addeventlistener(mouseevent.click,btnclick);
btna[0].dispatchevent(new mouseevent(mouseevent.click));
More discussions in ActionScript 3
adobe
Comments
Post a Comment