PDA

View Full Version : preload/setInterval /resizing/fading images code needs refining


yorkeylady
03-23-2003, 05:34 PM
Can someone check this fla for me.
This is the function that goes with my listbox:
function onClick(){
var num = _title.getSelectedIndex();
for(var i=0;i<listbox.getRowCount();i++){
if(num == testvalue){
//do something here
}
}
pic = _title.getValue();
_picbox.disappear(num, pic);
}

// this is in a MC called _picbox
stop();
//trace("in loadMC of picbox");
alph = 0;
function disappear(num, pic){
trace("in disappear("+num+", "+pic+")");
for(var i=0;i<_parent.listbox.getRowCount();i++){
if(num != i ){
if(this["pic_"+num]){
trace("setting "+num+" to invisible");
this["pic_"+num]._alpha = 0;
}
}
}
fadeimg(num,pic);
}

function fadeimg(num,pic){
//set the picture chosen to 100%
trace("in fadeimg("+num+", "+pic+")");
if(this["pic_"+num]){
this["pic_"+num]._alpha = 100;
fader2 = setInterval(bringin, 10, num);
}else{loadMC(num, pic)}
}
function bringin(num){
trace("in bringin("+num+")");
alph += 10;
this["pic_"+num]._alpha = alph;
if(alph >= 100){this["pic_"+num]._alpha = 100;
trace("clear interval fader2");
clearInterval(fader2);
}
}


function loadMC(num, pic){
trace("in loadMC("+num+", "+pic+")");

if(pic != ""){
trace("this visible false");
this._visible = false;
var j = num + 10;
trace("loading pic: "+pic);
this.createEmptyMovieClip("pic_"+num,j);
this["pic_"+num].loadMovie(pic, j);
preload(num);
}else{trace("pic variable isn't set :"+pic);}
}

function preload(num) {
trace("in preload("+num+")");
//preloader._visible = true;
//preloader._bar._xscale = 0;
//preloader.display.text = "0% loaded";
loadinter = setInterval(callback, 10, num);
}
function callback(num) {
trace("in callback("+num+")");
//this traces as undefined, it should have been created above in loadMC()
trace(this["pic_"+num]);
var download = this["pic_"+num].getBytesTotal();
var downloaded = this["pic_"+num].getBytesLoaded();
var percentLoaded = Math.cell(downloaded/download*100);
// preloader.display.text = percentLoaded+"% loaded";
// preloader.bar._xscale = percentLoaded;
updateAfterEvent();
trace("callback is called");
if (downloaded == download && download>0) {
//preloader._visible = false;
trace("setpicture is called");
clearInterval(loadinter);
setpicture(num, 275, 200, 0,0);
}
}

function setpicture(num, bw, bh, xp, yp){
trace("in setpicture");
var w = this["pic_"+num]._width;
var h = this["pic_"+num]._height;
var x = 0;
var y = 0;
if(w <= bw){
}else{
h = Math.round(h*bw/w);
w = bw;
}
if(h < 200){
}else{
w = Math.round(w*200/h);
h = bh;
}
if(h <= bh && w <= bw){
var center = ( bh - h)/2;
y = center;
center = (bw - w)/2;
x = center;
}
var al = 0;
with(this["pic_"+num]){
_width = w;
_height = h;
_x = xp+x;
_y = yp+y;
_alpha = 100;
}
trace("this visible true");
this._visible = true;
fader1 = setInterval(inload, 10, num);
}

function inload(num){
trace("inload alph: "+alph);
alph += 10;
this["pic_"+num]._alpha = alph;
if(alph > 80){
this["pic_"+num]._alpha = 100;
clearInterval(fader1);
}
}

yorkeylady
03-23-2003, 05:43 PM
oops, forgot to upload this