Im currently doing a Flash website, which required an animated background (The background is a few images rotating). The background needs to automatically scale according to the background window.
I have been able to do this with a .JPG by using the following code
import mx.transitions.Tween;import mx.transitions.easing.*;
var stageListener:Object=new Object();
stageListener.onResize=function(){
position();
};
Stage.align="TL";
Stage.scaleMode="noScale";
Stage.addListener(stageListener);
function position() {
// Find new value of stage size
var W:Number = Stage.width;
var H:Number = Stage.height;
// Find center of stage
var centerX:Number = W/2;
var centerY:Number = H/2;
background_mc._x = centerX;
background_mc._y = centerY;
background_mc.target_mc._x = -_global.BGW/2;
background_mc.target_mc._y = -_global.BGH/2;
content_mc._x = centerX;
content_mc._y = centerY;
var imageRatio:Number;
var imageXRatio = W/_global.BGW;
var imageYRatio = H/_global.BGH;
if (imageXRatio>imageYRatio) {
imageRatio = imageXRatio;
} else {
imageRatio = imageYRatio;
}
// Make the bg image go fullscreen
background_mc._xscale = background_mc._yscale=imageRatio*100;
}
// Function for smoothing resizable bitmaps
function smoothImageLoad(imgURL, targetMovie) {
var i = 0;
do {
i++;
} while (eval("_root.smoothImageLoadTemp"+i) != undefined);
tmc = targetMovie.createEmptyMovieClip("smoothImageLoadTemp"+i, targetMovie.getNextHighestDepth());
tmc.createEmptyMovieClip("ti",tmc.getNextHighestDepth());
tmc.tm = targetMovie;
with (tmc) {
tmcl = new MovieClipLoader();
tmcl.onLoadComplete = function() {
var fadeBG:Tween = new Tween(targetMovie, "_alpha", None.easeOut, 0, 100, 1, true);
ti.onEnterFrame = function() {
pixelData = new flash.display.BitmapData(ti._width, ti._height);
_global.BGW = ti._width;
_global.BGH = ti._height;
pixelData.draw(ti);
tm.attachBitmap(pixelData,1,true,true);
tm.smoothImageLoadComplete();
_parent._parent._parent.position();
removeMovieClip(ti._parent);
};
};
tmcl.loadClip(imgURL,tmc.ti);
}
}
smoothImageLoad("image.jpg",background_mc.target_mc);
I would want to do this with an SWF instead.
But simply changing the “image.jpg” to “imagerotator.swf”, doesn’t work.
Thanks in advance!