Files
bm/public_html/public/gallery/fla/Image.as
2025-09-24 13:26:28 +02:00

128 lines
3.3 KiB
ActionScript

class Image extends MovieClip{
private var file:String;
private var caption:String;
private var hyperlink:String;
private var container:MovieClip;
private var preloader:MovieClip;
private var bg:MovieClip;
private var captionBg:MovieClip;
private var captionText:TextField;
private var targetWidth:Number;
private var targetHeight:Number;
public static var FADE_STEP:Number = 5;
public static var RESIZE_STEP:Number = 5;
public static var PATH:String = "gallery/";
public static var MAX_HEIGHT:Number = 500;
public static var BORDER:Number = 10;
public function Image(){
container = this["container"];
preloader = this["preloader"];
captionBg = this["captionBg"];
captionText = this["captionText"];
bg = this["bg"];
container._alpha = 0;
captionBg._visible = false;
enabled = false;
}
public function loadImage(file:String, caption:String, hyperlink:String){
this.file = file;
this.caption = caption;
this.hyperlink = hyperlink;
fadeOut();
enabled = false;
onRollOut();
if(hyperlink.length > 0){
useHandCursor = true;
}
else{
useHandCursor = false;
}
}
public function fadeOut():Void{
this.onEnterFrame = function(){
container._alpha -= FADE_STEP;
if(container._alpha <= 0){
container._alpha = 0;
delete this.onEnterFrame;
preloader._visible = true;
startLoading();
}
}
}
public function fadeIn():Void{
this.onEnterFrame = function(){
container._alpha += FADE_STEP;
if(container._alpha >= 100){
container._alpha = 100;
delete this.onEnterFrame;
preloader._visible = false;
enabled = true;
}
}
}
public function startLoading():Void{
var loader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.image = this;
listener.onLoadInit = function(target:MovieClip){
this.image.resize();
}
loader.addListener(listener);
loader.loadClip(PATH + file, container);
}
public function resize():Void{
container._xscale = container._yscale = 100;
if(container._height > MAX_HEIGHT){
container._height = MAX_HEIGHT;
container._xscale = container._yscale;
}
targetWidth = Math.round(container._width + 2 * BORDER);
targetHeight = Math.round(container._height + 2 * BORDER);
this.onEnterFrame = function(){
bg._width += (targetWidth - bg._width)/RESIZE_STEP;
bg._height += (targetHeight - bg._height)/RESIZE_STEP;
if(Math.round(bg._width) == targetWidth && Math.round(bg._height) == targetHeight){
container._x = -container._width/2;
container._y = -container._height/2;
captionBg._width = container._width;
captionBg._y = container._height/2;
captionText._width = captionBg._width - 2 * BORDER;
captionText._x = -captionText._width/2;
captionText._y = captionBg._y - captionBg._height + 5;
delete this.onEnterFrame;
fadeIn();
}
}
}
public function onRollOver():Void{
if(caption.length > 0){
captionBg._visible = true;
captionText.text = caption;
}
}
public function onRollOut():Void{
captionBg._visible = false;
captionText.text = "";
}
public function onRelease():Void{
if(hyperlink.length > 0){
getURL(hyperlink, "_blank");
}
}
};