I was playing woith someone elses script and i kind of got it working to an
extent. The reason i am trying to preload *some* images is that there are
4000 plus records that i will be displaying in a table, which includes a
picture of each item. I would like to split it into pages displaying maybe
50 items max, but i don't know how to do that yet. Here is the kind of
working script i am playing with
<html>
<%
If IsObject(Session("Fragrance_conn")) Then
Set conn = Session("Fragrance_conn")
Else
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Fragrance","",""
Set Session("Fragrance_conn") = conn
End If
%>
<%
If IsObject(Session("retailU_rs")) Then
Set rs = Session("retailU_rs")
Else
sql = "SELECT * FROM [retailU]"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("retailU_rs") = rs
End If
%>
<head>
<script language="JavaScript1.2">
<!-- begin hiding
// (C) 2000 Marcin P Wojtowicz []. All rights reserved.
// Obtain permission before selling/redistributing in any medium.
startingColor = new Array() // <-- Do not modify!
endingColor = new Array() // <-- Do not modify!
// YOU MAY MODIFY THE FOLLOWING:
var yourImages = new Array() // Fill this array with the images you wish to
preload
<%
x = 0
On Error Resume Next
rs.MoveFirst
do while Not rs.eof //x <= 151
x = x + 1
response.write("yourImages[" & x & "]=" & "'" & rs("Images") & "';")
rs.MoveNext
loop
%>
document.write(yourImages.length);
var locationAfterPreload = "http://192.168.1.3/retail.asp" // The script
will redirect here when the preloading finishes *successfully*
var preloadbarWidth = 4000 // 151 The length of the preload bar. Should be
greater than total amount of images you want to preload!
var preloadbarHeight = 15 // The height of the gradient/preload bar
var backgroundOfGradient = "#000000" // Default color while the preload bar
is "filling up"
// Color the preloadbar is starting with - enter 1st, 3rd and 5th
numbers/letters of color code
startingColor[0] = "c"
startingColor[1] = "f"
startingColor[2] = "f"
// Color the preloadbar is going to end up with - enter the 1st, 3rd and 5th
numbers/letters of color code
endingColor[0] = "c"
endingColor[1] = "0"
endingColor[2] = "0"
// FOR TROUBLESHOOTING:
var gap = 2 // PLAY AROUND WITH THIS SETTING IF YOU GET A JAVASCRIPT
ERROR!!! 2 is the minumum value!!!
// DO NOT MODIFY ANYTHING BEYOND THIS POINT!!!
if (!document.all) location.replace(locationAfterPreload)
var a = 10, b = 11, c = 12, d = 13, e = 14, f=15, i, j, ones = new Array(),
sixteens = new Array(), diff = new Array();
var convert = new
Array("0","1","2","3","4","5","6","7","8","9","a", "b","c","d","e","f"),
imgLen = yourImages.length;
var loaded = new Array(), preImages = new Array(), currCount = 0, pending =
0, h = 0, hilite = new Array(), cover = new Array();
var num = Math.floor(preloadbarWidth/gap);
for (i = 0; i < 3; i++) {
startingColor[i] = startingColor[i].toLowerCase();
endingColor[i] = endingColor[i].toLowerCase();
startingColor[i] = eval(startingColor[i]);
endingColor[i] = eval(endingColor[i]);
diff[i] = (endingColor[i]-startingColor[i])/num;
ones[i] = Math.floor(diff[i]);
sixteens[i] = Math.round((diff[i] - ones[i])*15);
}
endingColor[0] = 0;
endingColor[1] = 0;
endingColor[2] = 0;
i = 0, j = 0;
while (i <= num) {
hilite[i] = "#";
while (j < 3) {
hilite[i] += convert[startingColor[j]];
hilite[i] += convert[endingColor[j]];
startingColor[j] += ones[j];
endingColor[j] += sixteens[j];
if (endingColor[j] > 15) {
endingColor[j] -= 15;
startingColor[j]++;
}
j++;
}
j = 0;
i++;
}
function loadImages() {
for (i = 0; i < imgLen; i++) {
preImages[i] = new Image();
preImages[i].src = yourImages[i];
loaded[i] = 0;
cover[i] = Math.floor(num/imgLen)*(i+1)
}
cover[cover.length-1] += num%imgLen
checkLoad();
}
function checkLoad() {
if (pending) { changeto(); return }
if (currCount == imgLen-1) { location.replace(locationAfterPreload);
return }
for (i = 0; i < imgLen; i++) {
if (!loaded[i] && preImages[i].complete) {
loaded[i] = 1; pending++; currCount++;
checkLoad();
return;
}
}
setTimeout("checkLoad()",10);
}
function changeto() {
if (h+1 > cover[currCount-1]) {
var percent = Math.round(100/imgLen)*currCount;
if (percent > 100) while (percent != 100) percent--;
if (currCount == imgLen && percent < 100) percent = 100;
defaultStatus = "Loaded " + currCount + " out of " + imgLen + " images ["
+ percent + "%].";
pending--;
checkLoad();
return;
}
eval("document.all.cell" + (h+1) + ".style.backgroundColor = hilite[h]");;
h++;
setTimeout("changeto()",1);
}
defaultStatus = "Loaded 0 out of " + imgLen + " images [0%]."
// end hiding -->
</script>
</head>
<body>
<center>
<font face="Verdana, Arial, Helvetica" size="2"><center>Preloading Images...
Please Wait..</center>
<script language="JavaScript1.2">
<!-- beging hiding
document.write('<table border="0" cellpadding="0" cellspacing="0" width="' +
preloadbarWidth + '"><tr height="' + preloadbarHeight + '" bgcolor="' +
backgroundOfGradient + '">');
for (i = 0; i < num; i++) {
document.write('<td width="' + gap + '" id="cell' + (i+1) + '"></td>');
}
document.write('</tr></table>');
document.write('<p><small><a
href="javascript
:location.replace(locationAfterPre load)">Skip Preloading</a>
| <a
href="http://javascriptkit.com/script/script2/preloadimage2.shtml">Script
Credits</a></small></p></font>')
loadImages();
// end hiding -->
</script>
</center>
</body>
</html>
"Brynn" <> wrote in message
news:.. .
> I agree ... check out my DBConn.asp script at the following ...
>
> http://www.coolpier.com/cp/cp_scripts/index.asp
>
> this gets you in and out of your database incredibly fast using the
> getrows method ... much faster than looping through a recordset at
> all. This way you wil build the string after your recordset and
> database connection is closed.
> GetRows will give you a 2-dimensional array of your recordset ...
> first dimension columns, second dimension rows. Yours just being 1
> column will be like the below loop. I would be sure to put Select
> Images From [retail]; instead of * ... if you don't need the other
> info.
>
> I recommend putting your connection string in an application variable
> via the global.asa ... or just set it on the page like so ...
>
> I like the way Tim got rid of last comma .. good idea Tim ... versus
> if .. then in the loop
>
> <!-- #include file="/coolpier_scripts/_database_tools/DBConn.asp" -->
>
> <%
> Dim yourSqlStatement, rsArray, strArray: strArray=""
> yourSqlStatement = "SELECT Images FROM [retail];"
>
> cp_TheConnectionString = "yourConnectionString"
> cp_DBConn(("open")
> rsArray = cp_SqlArray(yourSqlStatement)
> cp_DBConn("close")
>
> strImgBase = "http://www.mysite.com/images/"
> For n = 0 to ubound(rsArray,2)
> strArray = strArray & """" & strImgBase & rsArray(0,n) & ""","
> Next
> strArray=left(strArray,len(strArray)-1) '//to get rid of last comma
> %>
>
>
>
>
> On Thu, 08 Jan 2004 05:35:58 GMT, "Tim Williams"
> <> wrote:
>
> >Stuart,
> >
> >It's considered bad practise to store connection or recordset objects
> >objects in session variables (search relevant FAQ's for the reason).
> >It's much better to create connections as needed and to store data in
> >arrays rather than a rs.
> >
> >Anyway, once you have your recordset then just loop through it and add
> >the items:
> >
> >strImgBase = "http://www.mysite.com/images/"
> >strArr = ""
> >
> >if not rs.eof then
> >do while not rs.eof
> >
> >strArray = strArray & """" & _
> > strImgBase & rs("Images").value & ""","
> >
> >rs.movenext
> >loop
> >end if
> >
> >strArray=left(strArray,len(strArray)-1)
> >
> >
> >//then in the js preload script
> >var yourImages = new Array(<%=strArray%>) // Fill this array with the
> >images you wish to preload
> >
> >stuff strArray in a session (or application variable) to cache it for
> >the next use.
> >
> >
> >Tim.
> >
> >
> >"Stuart" <> wrote in message
> >news:bti22r$apn$...
> >> Hi there,
> >>
> >> I am trying to populate the array "yourImages" in the following
> >code,
> >> http://www.javascriptkit.com/script/...adimage2.shtml
> >> except i am trying to fill it with the values from an access
> >database.
> >> I already publish info from the database to an asp page, but i would
> >like to
> >> preload the images.
> >>
> >> I open the database successfully like this
> >> ---------------
> >> <%
> >> If IsObject(Session("Fragrance_conn")) Then
> >> Set conn = Session("Fragrance_conn")
> >> Else
> >> Set conn = Server.CreateObject("ADODB.Connection")
> >> conn.open "Fragrance","",""
> >> Set Session("Fragrance_conn") = conn
> >> End If
> >> %>
> >> <%
> >> If IsObject(Session("retail_rs")) Then
> >> Set rs = Session("retail_rs")
> >> Else
> >> sql = "SELECT * FROM [retail]"
> >> Set rs = Server.CreateObject("ADODB.Recordset")
> >> rs.Open sql, conn, 3, 3
> >> If rs.eof Then
> >> rs.AddNew
> >> End If
> >> Set Session("retail_rs") = rs
> >> End If"
> >> ---------------------
> >>
> >>
> >> The record i want to use is
> >> rs.Fields("Images").Value
> >>
> >> Could anyone please help me out?
> >>
> >>
> >>
> >> Thanks
> >>
> >>
> >>
> >
> >
>