codice:
//####################### CODICE #################->
dati = new LoadVars();
a = 1;
dati.onLoad = function(success){
if(success&&a==1){
arr = new Array() ;
_global.array_testo = this.array_testuale;
for(var a in dati){
if(a.substring(0,3) =='img'){
arr.push(this[a]);
}
}
trace(arr);
gallery.init(arr);
} else {
trace("errore caricamento");
// istruzioni per l'errore di caricamento
}
}
dati.load("file.txt");
//####################### CODICE #################<-
#include "com.qlod.LoaderClass.as"
#include "lmc_tween_as1.as"
loader = new com.qlod.LoaderClass();
loader.setMinSteps(8);
$tweenManager.broadcastEvents = true;
//$tweenManager.updateInterval = 15;
gallery = {};
gallery.init = function(varo) {
this.images= varo
trace(varo)
//trace(this.images)
this.data = [];
this.resize_controller = {};
this.resize_controller.clips = []; //
this.isAnimating = false;
this.imageborder = 4;
this.timeline = _root;
this.resizeClip = this.timeline.image_bg_mc;
this.contentClip = this.timeline.createEmptyMovieClip("image_mc", 500);
//
this.centerx = Stage.width/2;
this.centery = Stage.height/2;
//this.currentImageId = 0;
// if user press the next button on last picture it goes from 0
this.rotateMode = true;
this.buildNav();
this.preloadImages();
//attach credits
this.attachClip(credits, {right:0, bottom:0});
};
// call this functions from navigation functions
gallery.buildNav = function() {
var btnsize = 11;
var navHolder = this.timeline.createEmptyMovieClip("navHolder", 10);
//var gallery = this;
for (var i = 0; i<this.images.length; i++) {
var btn = navHolder.attachMovie("imgbtn", "img"+i, i);
btn._x = btnsize/2+btnsize*i;
btn.id = i;
btn.loaded = false;
btn.onPress = function() {
gallery.showImage(this.id);
};
btn.onRollOver = function() {
this.over_mc.gotoAndPlay("overanim");
};
btn.onRollOut = function() {
this.over_mc.gotoAndPlay("outanim");
};
btn.onLoadStart = function(loaderObj) {
this.gotoAndPlay("loading");
};
btn.onLoadProgress = function() {
gallery.data[this.id].mc._alpha = 0;
};
btn.onLoadComplete = function(success, loaderObj) {
this.loaded = true;
gallery.data[this.id].mc._visible = false;
if (this.id == 0) {
gallery.showImage(this.id);
}
};
btn.stop();
var mc = this.contentClip.createEmptyMovieClip("img"+i, i+10);
this.data[i] = {btn:btn, mc:mc};
}
// attach nav top left
this.attachClip(navHolder, {center:-navHolder._width/2, top:-6});
};
gallery.preloadImages = function() {
var gallery = this;
for (var i = 0; i<this.images.length; i++) {
loader.load(this.data[i].mc, this.images[i], this.data[i].btn);
}
};
gallery.showNext = function() {
this.loadImage(this.currentImageId+1);
};
gallery.showPrev = function() {
this.loadImage(this.currentImageId-1);
};
gallery.showImage = function(id) {
if (id>=this.images.length) {
if (this.rotateMode) {
id = 0;
} else {
return;
}
} else if (id<0) {
if (this.rotateMode) {
id = this.images.length-1;
} else {
return;
}
}
//
if (this.currentImageId == undefined) {
this.currentImageId = id;
this.showNewImage();
} else {
if (this.isAnimating) {
this.nextToShow = id;
} else {
this.nextToShow = undefined;
this.prevImageId = this.currentImageId;
this.currentImageId = id;
this.hideOldImage();
}
}
};
gallery.hideOldImage = function() {
trace("hideold"+this.prevImageId);
//this.data[this.prevImageId].mc.stopTween()
this.isAnimating = true;
this.data[this.prevImageId].mc.alphaTo(0, 1, undefined, 0, {func:this.showNewImage, scope:this});
};
gallery.showNewImage = function() {
trace("shownew"+this.currentImageId);
var mc = this.data[this.currentImageId].mc;
// is loaded
if (this.data[this.currentImageId].btn.loaded) {
with (this) {
contentClip._x = centerx-mc._width/2;
contentClip._y = centery-mc._height/2;
//
this.data[this.prevImageId].mc._visible = false;
mc._visible = true;
mc.alphaTo(100, 1, undefined, 1, function () {
gallery.isAnimating = false;
trace(gallery.isAnimating)
if (gallery.nextToShow != undefined) {
gallery.showImage(gallery.nextToShow);
}
});
//
var dx = centerx-mc._width/2-imageborder;
var dy = centery-mc._height/2-imageborder;
var dw = mc._width+2*imageborder;
var dh = mc._height+2*imageborder;
resizeClip.tween(["_x", "_y", "_width", "_height"], [dx, dy, dw, dh], 1, "easeoutexpo");
}
} else {
// break preloading and load mc
loader.clear();
// load first the clicked image
var i = this.currentImageId;
this.data[i].btn.onLoadComplete = function(success, loaderObj) {
this.loaded = true;
gallery.showImage(this.id);
};
loader.load(this.data[i].mc, this.images[i], this.data[i].btn);
// continue the rest
for (var j = 0; j<this.images.length; j++) {
if (i != j && !this.data[j].btn.loaded) {
loader.load(this.data[j].mc, this.images[j], this.data[j].btn);
}
}
}
};
//function to attach clips to move with image bg
//alignObj parameters
// mc - movieclip reference
// attaching points + relative positions
// left, right, center - numbers
// top, bottom, middle - numbers
gallery.attachClip = function(mc, alignObj) {
if (this.resize_controller.clips.length == 0) {
this.resize_controller.baseClip = this.resizeClip;
this.resize_controller.onTweenUpdate = function() {
for (var i in this.clips) {
var mc = this.clips[i].mc;
var align = this.clips[i].align;
if (align.left != undefined) {
mc._x = align.left+this.baseClip._x;
} else if (align.center != undefined) {
mc._x = align.center+this.baseClip._x+(this.baseClip._width/2);
} else if (align.right != undefined) {
mc._x = align.right+this.baseClip._x+this.baseClip._width;
}
if (align.top != undefined) {
mc._y = align.top+this.baseClip._y;
} else if (align.middle != undefined) {
mc._y = align.middle+this.baseClip._y+(this.baseClip._height/2);
} else if (align.bottom != undefined) {
mc._y = align.bottom+this.baseClip._y+this.baseClip._height;
}
}
};
this.resizeClip.addListener(this.resize_controller);
}
this.resize_controller.clips.push({mc:mc, align:alignObj});
this.resize_controller.onTweenUpdate();
};
gallery.deatachClip = function(mc) {
for (var i in this.resize_controller.clips) {
//
}
};
//