单击SharedObject,单击每个用户按钮

时间:2014-05-18 01:36:56

标签: actionscript-3 flash real-time shared-objects mouseclick-event

我有一个imageslider.swf,它有2个按钮。 nextBtn用于传递下一个图像,而prevBtn用于返回上一个图像。这个swf实际上是幻灯片分享应用程序。我希望当演示者按下任何一个按钮时,每个幻灯片都会改变(在每个客户端上)。但这将发生在互联网上。不在本地网络上。

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.filters.GlowFilter;
import flash.filters.DropShadowFilter;
import flash.utils.Timer;
import flash.events.TimerEvent;




//*****************DECLARING ALL VARIABLES*****************************//

//the array has all picture labels
var myArray:Array = ["Barbecued Chicken", "Bread & Rolls", "Burger", "Chicken Chilly" , "Awesome fish"];
var myGlow:GlowFilter = new GlowFilter(0xffffff,1,10,10,255);// saving the glow
var myShadow:DropShadowFilter = new DropShadowFilter(6);// saving the shadow to be applied later
var totalImages=11;
var imageNumber=1;
var myTimer:Timer = new Timer(4000);// 4 second timer
var myLoader:Loader = new Loader();


//************FETCHING THE PICTURES LYING IN THE EXTERNAL FOLDER********************//

var myRequest:URLRequest = new URLRequest("Images/"+imageNumber+".jpg");
myLoader.load(myRequest);
addChildAt(myLoader,1);// will be added under the buttons layer but over the texture

//************CENTERING THE PICS AND APPLYING BORDER AND DROP SHADOW****************//

myLoader.contentLoaderInfo.addEventListener(Event.INIT, getImageInfo);
function getImageInfo(event:Event){
    var imgX=(stage.stageWidth- myLoader.width)/2;
    var imgY=(stage.stageHeight- myLoader.height)/2;
    myLoader.x=imgX;
    myLoader.y = imgY;// lines 37,38,39 & 40 are centering the loader formulae
    myLoader.filters = [myGlow, myShadow];// adding a white color glow / grey shadow
    var myTween:Tween = new Tween(myLoader, "alpha", None.easeNone, 0,1,2,true);//apply fade in

    }
//**************AUTOMATIC PROGRESSION ********************************//

myTimer.addEventListener(TimerEvent.TIMER, autoadvance);
function autoadvance(event:TimerEvent){
    if(imageNumber<totalImages){imageNumber++}
    else (imageNumber=1);
    reload();   
}
myTimer.start();

//**************GOING TO NEXT IMAGE********************************//

rightButton.addEventListener(MouseEvent.CLICK, nextImage);
function nextImage(event:MouseEvent){
    if(imageNumber<totalImages){imageNumber++}
    else (imageNumber=1);
    reload();
        }
    //**************GOING TO PREVIOUS IMAGE********************************//

leftButton.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent){
    if(imageNumber>1){imageNumber--}
    else (imageNumber=totalImages);
    reload();
    }

    //*****************controlling THE THUMBNAILS****************************//

t1.addEventListener(MouseEvent.CLICK, thumbHandler);
t2.addEventListener(MouseEvent.CLICK, thumbHandler);
t3.addEventListener(MouseEvent.CLICK, thumbHandler);
t4.addEventListener(MouseEvent.CLICK, thumbHandler);
t5.addEventListener(MouseEvent.CLICK, thumbHandler);

function thumbHandler(event:MouseEvent){
         if(event.currentTarget==t1){imageNumber=1}
        else    if(event.currentTarget==t2){imageNumber=2}
        else  if(event.currentTarget==t3){imageNumber=3}
        else  if(event.currentTarget==t4){imageNumber=4}
        else{imageNumber=5}
        reload();
    }

    //**************REPLACING OLD IMAGE WITH NEW ********************************//

function reload(){
    removeChild(myLoader);
    myRequest= new URLRequest("Images/"+imageNumber+".jpg");
    myLoader.load(myRequest);
    addChildAt(myLoader,1);
    //changing the label and tweening with as 3
    myLabel.pictureLabel.text = myArray[imageNumber-1];
    var tweenLabel:Tween = new Tween(myLabel, "rotation", Bounce.easeOut,  360, 390,1,true)
    }

//***************PLAYING MUSIC PLACED EXTERNALLY*******************************//
var my_sound:Sound = new Sound();
my_sound.load(new URLRequest("soothing_music.mp3"));
var my_channel:SoundChannel = new SoundChannel();
my_channel = my_sound.play(0,9999);// 9999 is the number of times the music should loop.

    //*********DETECTING IF MOUSE IS ON THE STAGE TO STOP/RESUME TIMER***********//
    //stopping the timer.
    stage.addEventListener(MouseEvent.MOUSE_MOVE, stop_the_Timer);
    function stop_the_Timer(event:MouseEvent){
    myTimer.stop();
    }
    //resume timer
    stage.addEventListener(Event.MOUSE_LEAVE, resumeTimer);
    function resumeTimer(event:Event){
    myTimer.start();
    }

0 个答案:

没有答案