We help IT Professionals succeed at work.
Get Started

Preloading Images all at once into a container

fritzer17
fritzer17 asked
on
173 Views
Last Modified: 2010-04-03
The following is a script that I am currently using to load images into the
container named "lgpicture" (first part) and then to operate buttons, both
individually and as "next_btn" or "previous_btn" buttons (2nd part).  The
problem is that I need the images, which are being loaded externally from an
.xml file, to preload all at once into the container "lgpicture" rather than
individually (as they are viewed).  Because the images are well over 500K
and the client is unwilling to compromise on the quality of the images,
there is a long pause between viewing each image the first time each button
is pushed.  He is okay with a long pause in the beginning with a percentage
preloader bar, but not the pause between each image as they are viewed.  I
need to know if it would be possible to adjust the following script to
preload all images at once.
Thanks in advance for any advice you can give:

lgpicture._x=0;
lgpicture._y=30;
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images1lg.xml");
/////////////////////////////////////


/////////////////////////////////////
p = 0;
this.onEnterFrame = function() {
filesize = lgpicture.getBytesTotal();
loaded = lgpicture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (lgpicture._alpha<100) {
lgpicture._alpha += 10;
}
}
};
function firstImage() {
if (loaded == filesize) {
lgpicture._alpha = 0;
lgpicture.loadMovie(image[0], 1);
desc_txt.text = description[0];
lgpicture_num();
}
}
function lgpicture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}




// initialize the variable

var p = 1;

//

for (var i = 1; i <= 23; i++)

{

var button = eval("button" + i);

button.i = i;

button.onPress = function()

{

resetAllButtons();

this._alpha = 100;

this.enabled = false;

if (loaded == filesize)

{

lgpicture._alpha = 0;

lgpicture.loadMovie(image[this.i - 1], 1);

desc_txt.text = description[this.i - 1];

lgpicture_num();

}

// change the value of p

p == this.i -1 ;

};

}
if (p = 1) {
button1._alpha = 100;
} else {
button1._alpha = 30;
}

// this appears outside the for() loop

listen = new Object();

listen.onKeyDown = function()

{

if (Key.getCode() == Key.LEFT)

{

prevImage();

}

else if (Key.getCode() == Key.RIGHT)

{

nextImage();

}

};

Key.addListener(listen);

previous_btn.onRelease = function()

{

prevImage();

};

next_btn.onRelease = function()

{

nextImage();

};

//

function nextImage() {
if (p < 23) {
p++;
} else {
p = 1;
}
eval("button" + p).onPress();
}

function prevImage() {
if (p > 1){
p--;
} else {
p = 23;
}
eval("button" + p).onPress();
}

function resetAllButtons()

{

for (var i = 1; i <= 23; i++)

{

var button = eval("button" + i);

button._alpha = 30;

button.enabled = true;

}

}
stop();


Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE