Action Script 21 Jul 2006 08:44 am
Slide Show Class for Dynamic Image Gallery updated
(Visited 8633 times)May be you already read my post about Slide Show Class for Dyanmic Image Gallery.
Now the class is update which are now has horizontal and vertical slide fx available.
Actionscript:
-
//
-
// Slide Show Tween Class V2
-
//
-
class janumedia.fx.tween {
-
-
private var mc:MovieClip; // target mc
-
private var mask1:MovieClip; // mask1
-
private var mask2:MovieClip; // mask2
-
private var img1:MovieClip; // mc1
-
private var img2:MovieClip; // mc2
-
private var border:MovieClip; // border mc
-
private var width:Number; // width
-
private var height:Number // height
-
private var orientation:String; // slide orientation
-
private var data:Array; // image gallery
-
private var speed:Number; // tween speed interval
-
private var cur:Number; // current play
-
private var tw:Boolean; // tween status
-
private var intervalID;
-
-
function tween(t:MovieClip,d:Array,s:Number,o,w:Number,h:Number){
-
// t = movieclip target ; d = image list in array ; s = swening speed interval in sec ;
-
// o = orientation --> available : "alpha" => alpha, "x" => horizontal, "y" => vertical
-
// w = witdh , h = height
-
mc = t.createEmptyMovieClip("mainSlide",t.getNextHighestDepth());;
-
data = d;
-
speed = s;
-
cur = 0;
-
tw = false;
-
width = w;
-
height = h;
-
orientation = o == undefined ? "alpha" : o;
-
prepared();
-
}
-
private function prepared(){
-
img1 = mc.createEmptyMovieClip("img1",10);
-
img2 = mc.createEmptyMovieClip("img2",9);
-
img1.createTextField("status",10,200,125,10,10);
-
img2.createTextField("status",10,200,125,10,10);
-
-
// set masking if the value is available
-
if(width != undefined and height != undefined) addMask(mc,0,0,width,height);
-
-
if(data.length>= 1){
-
var theImg = nextImage();
-
if(theImg != "" && theImg != undefined ){
-
deleteNoImage(img1);
-
loadImage(img1,theImg);
-
} else {
-
noImage(img1);
-
}
-
}
-
-
if(data.length>= 2){
-
var theImg = nextImage();
-
if(theImg != "" && theImg != undefined ){
-
deleteNoImage(img2);
-
loadImage(img2,theImg);
-
} else {
-
noImage(img2);
-
}
-
}
-
-
}
-
private function beginTween(n:MovieClip){
-
clearInterval(intervalID);
-
//trace("begin tween "+n);
-
-
switch(n){
-
case img1 :
-
img2.owner = this;
-
img2.onEnterFrame = function(){ this.owner.doSlide(this); }
-
break
-
case img2 :
-
img1.owner = this;
-
img1.onEnterFrame = function(){ this.owner.doSlide(this); }
-
break;
-
}
-
}
-
-
private function doSlide(t:MovieClip){
-
-
switch(orientation){
-
case "alpha":
-
//trace("tween for "+t._name);
-
t._x = 0;
-
t._y = 0;
-
t._alpha -= speed;
-
var otherImg = eval( t._name == "img1" ? img2 : img1 );
-
with(otherImg){
-
_x = 0;
-
_y = 0;
-
}
-
if(t._alpha <= 0) {
-
t.swapDepths(9);
-
otherImg.swapDepths(10);
-
delete t.onEnterFame;
-
var theImg = nextImage();
-
if(theImg != "" && theImg != undefined ){
-
deleteNoImage(t);
-
loadImage(t,theImg);
-
} else {
-
noImage(t);
-
}
-
}
-
break;
-
case "x":
-
t._y = 0;
-
t._x -= speed;
-
t._alpha = 100;
-
var otherImg = eval( t._name == "img1" ? img2 : img1 );
-
with(otherImg){
-
_x = t._x + t._width;
-
_y = 0;
-
_alpha = 100;
-
}
-
if(t._x <= - t._width ) {
-
delete t.onEnterFame;
-
var theImg = nextImage();
-
if(theImg != "" && theImg != undefined ){
-
deleteNoImage(t);
-
loadImage(t,theImg);
-
} else {
-
noImage(t);
-
}
-
}
-
break;
-
case "y":
-
t._x = 0;
-
t._y -= speed;
-
t._alpha = 100;
-
var otherImg = eval( t._name == "img1" ? img2 : img1 );
-
with(otherImg){
-
_x = 0;
-
_y = t._y + t._height;
-
_alpha = 100;
-
}
-
-
if(t._y <= - t._height ) {
-
delete t.onEnterFame;
-
var theImg = nextImage();
-
if(theImg != "" && theImg != undefined ){
-
deleteNoImage(t);
-
loadImage(t,theImg);
-
} else {
-
noImage(t);
-
}
-
}
-
break;
-
}
-
}
-
-
private function nextImage():String{
-
var n = cur;
-
cur++;
-
cur = cur>= data.length ? 0 : cur;
-
//trace("cur : "+cur+" : "+data[n]);
-
return data[n];
-
}
-
-
private function loadImage(t:MovieClip,img){
-
//trace("load : "+img+" to : "+t);
-
-
t._parent.status.autoSize = "center";
-
t._parent.status.embedFonts = true;
-
var fmt:TextFormat = new TextFormat();
-
fmt.font = "Arial"
-
t._parent.status.setTextFormat(fmt);
-
-
var my_mcl = new MovieClipLoader();
-
var myListener = new Object();
-
myListener.owner = this;
-
myListener.onLoadComplete = function (tmc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
-
tmc._alpha = 100;
-
if(this.owner.tw) this.owner.intervalID = setInterval(this.owner,"beginTween",speed * 1000,tmc);
-
this.owner.tw = true;
-
}
-
myListener.onLoadProgress = function(tmc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
-
var a = Math.round((bytesLoaded/bytesTotal)*100);
-
t._parent.status.text = a+"%";
-
//trace("load progress ");
-
}
-
my_mcl.addListener(myListener);
-
my_mcl.loadClip(img, t);
-
}
-
-
private function deleteNoImage(t:MovieClip){
-
removeMovieClip(t.noimage);
-
}
-
-
private function noImage(t:MovieClip){
-
// trace("no image");
-
var x = 0;
-
var y = 0;
-
var w = 399;
-
var h = 250;
-
t.createEmptyMovieClip("noimage", 123456);
-
var mc = t.noimage;
-
with(mc){
-
beginFill(0xFFFFFF);
-
lineStyle(0, 0xC9C9C9);
-
moveTo(x, y);
-
lineTo(w, y);
-
lineTo(w, h);
-
lineTo(x, h);
-
lineTo(x, y);
-
endFill();
-
}
-
mc.createTextField("status",10,mc._width/2,(mc._height/2)-14,10,10);
-
with(mc.status){
-
autoSize = "center";
-
text = "no image";
-
embedFonts = true;
-
selectable = false;
-
textColor = 0xC9C9C9;
-
}
-
-
var fmt:TextFormat = new TextFormat();
-
with(fmt){
-
font = "Arial";
-
size = 14;
-
}
-
mc.status.setTextFormat(fmt);
-
}
-
-
private function addMask(t:MovieClip,x,y,w:Number,h:Number){
-
-
var mask = t.createEmptyMovieClip("mask_mc", t.getNextHighestDepth());
-
with(mask){
-
beginFill(0xFF0000);
-
moveTo(x, y);
-
lineTo(w, y);
-
lineTo(w, h);
-
lineTo(x, h);
-
lineTo(x, y);
-
endFill();
-
}
-
t.setMask(mask);
-
}
-
-
public function move(x:Number,y:Number):Void{
-
mc._x = x;
-
mc._y = y;
-
}
-
-
public function set mode(t:String){
-
orientation = t;
-
}
-
-
public function drawBorder(s:Number,w:Number,h:Number,c):Void{
-
border = mc.createEmptyMovieClip("border_mc", mc.getNextHighestDepth());
-
with(border){
-
lineStyle(s,c);
-
moveTo(0, 0);
-
lineTo(w, 0);
-
lineTo(w, h);
-
lineTo(0, h);
-
lineTo(0, 0);
-
}
-
}
-
-
public function clearBorder(s:Number,w:Number,h:Number,c):Void{
-
border.clear();
-
}
-
}
How to use it? Simple is much the same as the old version all you need to add is the fx / orientation, also add masking if you want it.
Actionscript:
-
// sample 1 vertical slide show
-
var slideShow = new janumedia.fx.tween(this,["image1.jpg","image2.jpg"],1,"y",320,250);
Actionscript:
-
// sample 2 horisonal slide show
-
var slideShow = new janumedia.fx.tween(this,["image1.jpg","image2.jpg"],1,"x",320,250);
Actionscript:
-
// sample 3 alpha fx slide show
-
var slideShow = new janumedia.fx.tween(this,["image1.jpg","image2.jpg"],1,"alpha",320,250);
Online example and get source
12 Responses to “Slide Show Class for Dynamic Image Gallery updated”
Leave a Reply
You must be logged in to post a comment.


on 01 Oct 2006 at 4:40 pm 1.SpecialK said …
is it possible to make a pause between each transitions ?
on 04 Oct 2006 at 5:25 am 2.janu said …
Well offcourse possible.
since the tweening base onEnterFrame event you can put some variable there
somekind like:
on 06 Oct 2006 at 3:29 pm 3.SpecialK said …
thank you for your answer.
But I want to make a pause without controller, like a setInterval...
on 03 Jan 2007 at 3:55 am 4.mantra said …
perkenalkan saya mantra,script di atas saya pengen terapkan di website saya bli , gimana caranya load xml data,dan pada thumbnail bisa ke detail page php yang saya pakai .mohon pencerahan
on 17 Jan 2007 at 3:08 am 5.janumedia said …
dear mantra. mohon maaf belakangan ini saya amat sibuk.
soal penggunaan xml sebenernya beberapa temen sempat bertanya pada saya. hari ini saya upload versi load data dari xml filenya ada di http://janumedia.com/source/AS2/SlideShowClass-v2a.zip
Good luck utk website dan art worknya
on 05 Mar 2007 at 5:07 pm 6.Geraint said …
Great Code thanks!
How would i go about putting a pause between each transitions?
Regards Geraint
on 17 Mar 2007 at 11:04 am 7.Nicolas said …
¡Muy buen trabajo!
Muchas gracias
on 02 Apr 2007 at 10:41 am 8.sonny said …
hallo mas,berapa image yang maksimal di tampung?
on 19 Apr 2007 at 4:05 am 9.sam said …
Great Class! I was wondering if it is possible to have the slideshow change image after a certain period of time instead of moving to the next image right away. Like a pause.
Also, is it possible to have controllers? (next, previous, play/pause)
Thanks in Advance.
on 11 Jun 2007 at 5:11 pm 10.mario said …
Hi Janumedia.
Is there any chance you will be able to answer the questions regarding the pause between images?
Thanks for the great class
on 12 Jun 2007 at 6:34 pm 11.Janu said …
Hi mario,
sure it is possible, please read my reply commment above
on 13 Dec 2007 at 2:47 pm 12.zsolt said …
Hi Janu,
I have also interest in putting a setinterval ( wait ) in the class, and not in the .fla with buttons
Is it possible to change the loadImage function to wait 5 sec before the tween?