Marta
H.
Fotograf/Grafik
komputerowy/Webmaste
r
Temat: AS3 - Galeria odtwarza się od początku, a nie od...
Witam!Czy ktoś mógłby mi poradzić, jak powinnam poprawić kod poniższy aby działał poprawianie, czyli tak aby po kliknięciu na przycisk next bądź previous pokazywało mi się kolejne zdjęcie, a nie odtwarzała mi się galeria od początku. Niestety nie bardzo się orientuje jak to zrobić, a siedzę na tym już jakiś czas. Będę wdzięczna za pomoc.
stop();
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import fl.containers.UILoader;
import fl.containers.UILoader;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
TweenPlugin.activate([TintPlugin]);
var numerFoto:uint;
//---------loading the external xml file-------
var urlRequest:URLRequest = new URLRequest("Photo.xml");
var urlLoader:URLLoader = new URLLoader();
var myXML:XML = new XML();
var xmlList:XMLList;
myXML.ignoreWhitespace = true;
urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
urlLoader.load(urlRequest);
//--------holds the paths to the thumbnails-------;
var arrayURL:Array = new Array();
//--------holds the paths to the big photos-------
var arrayName:Array = new Array();
//--------holds the thumbnail objects-------
var holderArray:Array = new Array();
//--------represents the number of collumns-------
var nrColumns:uint = 7;
//-------represents the container of our gallery
var sprite:Sprite = new Sprite();
addChild(sprite);
var thumb:Thumbnail;
//-------- the thumbnails container-------
var thumbsHolder:Sprite = new Sprite();
sprite.addChild(thumbsHolder);
//-------- the photoLoader container-------;
var loaderHolder:Sprite = new Sprite();
loaderHolder.graphics.beginFill(0x000000);
loaderHolder.graphics.endFill();
loaderHolder.x = 15.5;
loaderHolder.y = -800;
sprite.addChild(loaderHolder);
//-------- loads the big photo-------;
var photoLoader:UILoader = new UILoader();
photoLoader.width = 881;
photoLoader.height = 525;
photoLoader.x = 15.5;
photoLoader.y = 0;
photoLoader.buttonMode = true;
loaderHolder.addChild(photoLoader);
var xphoto:photo = new photo();
xphoto.x = 880;
xphoto.y = 10;
xphoto.addEventListener(MouseEvent.CLICK,onClickClose);
photoLoader.addChild(xphoto);
var xnext:next = new next();
xnext.x = 891;
xnext.y = 227.50;
xnext.addEventListener(MouseEvent.CLICK,onClickNext);
photoLoader.addChild(xnext);
var xprevious:previous = new previous();
xprevious.x = -30;
xprevious.y = 227.50;
xprevious.addEventListener(MouseEvent.CLICK,onClickPrevious);
photoLoader.addChild(xprevious);
/* we loop through the xml file
populate the arrayURL, arrayName and position the thumbnalis */
function fileLoaded(event:Event):void
{
myXML = XML(event.target.data);
xmlList = myXML.children();
for (var i:int=0; i<xmlList.length(); i++)
{
var picURL:String = xmlList[i].url;
var picName:String = xmlList[i].big_url;
arrayURL.push(picURL);
arrayName.push(picName);
holderArray[i] = new Thumbnail(arrayURL[i],i,arrayName[i]);
holderArray[i].addEventListener(MouseEvent.CLICK,onClick);
holderArray[i].name = arrayName[i];
holderArray[i].buttonMode = true;
if (i<nrColumns)
{
holderArray[i].y = 98;
holderArray[i].x = i * 126 + 90;
}
else
{
holderArray[i].y = holderArray[i - nrColumns].y + 165;
holderArray[i].x = holderArray[i - nrColumns].x;
}
thumbsHolder.addChild(holderArray[ i ]);
}
}
//----handles the Click event added to the thumbnails--
function onClick(event:MouseEvent):void
{
photoLoader.source = event.currentTarget.name;
TweenLite.to(thumbsHolder, 0, {y:0, ease:Bounce.easeOut});
TweenLite.to(loaderHolder, 0, {y:0, ease:Elastic.easeOut});
TweenLite.to(thumbsHolder, 0, {alpha:0, ease:Elastic.easeOut});
TweenLite.to(loaderHolder, 0, {alpha:1, ease:Elastic.easeOut});
}
//----handles the Click event added to the photoLoader----
function onClickClose(event:MouseEvent):void
{
TweenLite.to(thumbsHolder, 0, {y:0, ease:Bounce.easeOut});
TweenLite.to(loaderHolder, 0, {y:-1000, ease:Elastic.easeOut});
TweenLite.to(thumbsHolder, 0, {alpha:1, ease:Elastic.easeOut});
TweenLite.to(loaderHolder, 0, {alpha:0, ease:Elastic.easeOut});
}
function onClickNext(event:MouseEvent):void
{
numerFoto++;
if (numerFoto == 25)
{
numerFoto = 1;
}
photoLoader.source = "pics/" + numerFoto + ".jpg";
}
function onClickPrevious(event:MouseEvent):void
{
numerFoto--;
if (numerFoto == 1)
{
numerFoto = 25;
}
photoLoader.source = "pics/" + numerFoto + ".jpg";
}