Hey Gordon...
Sorry for not posting for a few days. Had some personal things to deal with. Anyway, let's get back with this.
To refresh: We currently have an XML powered "slideshow" that loads up to 3 images per page and then adds pagination functionality.
Now we're looking to add some visual interest and tie up some loose ends. As mentioned before, we'll be using MC Tween to perform all the tweening. There are other tweening engines out there -- including Flash's native Tween class -- but I'm most fond of MC Tween for use with AS 2.
First, we "include" MC Tween so we can access its methods:
Code:
// Import MC Tween
#include "mc_tween2.as"
Next, let's animate the "loading" message. Currently, we have it being set to be invisible within the onLoadInit() method call. Using MC Tween, let's fade the "loading" message out.
Code:
listener.onLoadInit = function(target) {
target._parent.loading.alphaTo(0, .75, "easeOutQuad");
}
This uses an alpha tween to go from loading's current alpha state to 0% alpha transparency over .75 seconds using an "easeOutQuad" animation type. Go over the MC Tween documentation for more about animation/ease types.
Ok, so now it fades. Like you mentioned before, this only happens the first time. That is because once it's tweened, it's alpha is at 0. Therefore, there is no need to tween it again. So, we should reset the alpha transparency before we tween it.
Code:
// Load Images
function loadImages(page) {
pageNo.text = "PAGE " + (page+1) + " OF " + total;
for(i=0;i<3;i++) {
positions[i].loading.alphaTo(100, .75, "easeOutQuad");
var imagePath:String = path + xml.firstChild.childNodes[page].childNodes[i].childNodes
if(imagePath!=path) {
var loader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = function(target) {
target._parent.loading.alphaTo(0, .75, "easeOutQuad");
}
loader.addListener(listener);
loader.loadClip(imagePath,positions[i].holder);
}
}
}
Alright, great! Now we have the "loading" message showing where there is no image to be loaded. Instead of showing that, let's fade out that particular "frame". We have a conditional that tests to see if an image is to be loaded within a frame. We can utilize that to set an "else" conditional in case the "frame" is empty.
Code:
// Load Images
function loadImages(page) {
pageNo.text = "PAGE " + (page+1) + " OF " + total;
for(i=0;i<3;i++) {
positions[i].loading.alphaTo(100, .75, "easeOutQuad");
var imagePath:String = path + xml.firstChild.childNodes[page].childNodes[i].childNodes
if(imagePath!=path) {
var loader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = function(target) {
target._parent.loading.alphaTo(0, .75, "easeOutQuad");
}
loader.addListener(listener);
loader.loadClip(imagePath,positions[i].holder);
}
else {
positions[i].alphaTo(0, .5, "easeOutQuad");
}
}
}
Now test and you'll find that once a "frame" is faded out, it stays that way. Again, we need to reset the alpha of the positions[i] movieclip.
Code:
// Load Images
function loadImages(page) {
pageNo.text = "PAGE " + (page+1) + " OF " + total;
for(i=0;i<3;i++) {
positions[i].loading.alphaTo(100, .75, "easeOutQuad");
var imagePath:String = path + xml.firstChild.childNodes[page].childNodes[i].childNodes
if(imagePath!=path) {
positions[i].alphaTo(100, .5, "easeOutQuad");
var loader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadInit = function(target) {
target._parent.loading.alphaTo(0, .75, "easeOutQuad");
}
loader.addListener(listener);
loader.loadClip(imagePath,positions[i].holder);
}
else {
positions[i].alphaTo(0, .5, "easeOutQuad");
}
}
}
There you have it. You should now have the fade-in/out that you were looking for. Post back with any questions.
Bookmarks