Hjælp til preloader
var imageLoader:Loader;var imageLoader1:Loader;
var xml:XML;
var galleriWidth: Number;
galleriWidth = 0;
var nowWidth: Number = 0;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
//Aktiver ved brug på ftp
//xmlLoader.load(new URLRequest("images.xml?nocache=" + new Date().getTime()));
//Aktiver ved lokal test
xmlLoader.load(new URLRequest("images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
var Gallery:Gallery_mc;
Gallery = new Gallery_mc();
addChild(Gallery);
Gallery.x=0;
Gallery.y=1;
for(var i:int = 0; i < xmlList.length(); i++)
{
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("source")));
nowWidth = xml.image[i].@galWidth;
imageLoader.x =galleriWidth;
imageLoader.y = 3;
Gallery.addChild(imageLoader);
imageLoader1 = new Loader();
imageLoader1.load(new URLRequest(xmlList[i].attribute("source")));
imageLoader1.x = 2338 + galleriWidth;
imageLoader1.y = 3;
Gallery.addChild(imageLoader1);
galleriWidth += nowWidth + 10;
setChildIndex(Gallery, 0);
}
}
//Det er denne funktion der skal kaldes når billederne er blevet loaded.
knap.addEventListener(MouseEvent.CLICK, startGalleri);
function startGalleri(event:MouseEvent):void
{
var centerX:Number = stage.stageWidth / 2;
var galleryWidth:Number = Gallery.width;
var speed:Number = -1;
genLayer.addEventListener(MouseEvent.MOUSE_OVER, stopGallery);
genLayer.addEventListener(MouseEvent.MOUSE_OUT, startGallery);
addEventListener(Event.ENTER_FRAME, moveGallery);
function stopGallery(Event:MouseEvent): void
{
speed = 0;
}
function startGallery(Event:MouseEvent): void
{
speed = -1;
}
function moveGallery(e:Event):void
{
Gallery.x+=speed;
if (Gallery.x>0)
{
Gallery.x= (-galleryWidth/2);
}
if (Gallery.x<(-galleryWidth/2))
{
Gallery.x=0;
}
}
}