Closed Thread Icon

Topic awaiting preservation: why does my variable keep getting reset? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8258" title="Pages that link to Topic awaiting preservation: why does my variable keep getting reset? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: why does my variable keep getting reset? <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-12-2002 05:37

For some reason, a variable keeps getting reset to 0, and I can't figure out why. Here's my intention/theory:

I call the compileMessage() function, which, at the end, calls the writetolayer() function. The FIRST time this runs, I need var blah == 0, and it is (I initialize it above this code. Anyways, after the compileMessage() function runs, and finishes with the writetolayer() function, I set blah to 1. My theory is that the NEXT time that this runs, blah ==1, and thus, some other code gets executed. However, I'm finding that blah==0 each time I run this, except at the end, when I set it to 1. The next time, it's back at 0 again, and I can't figure out why.

This is part of my cool slideshow/picture viewer app, and these are two of many functions in this app. Everything works except this part, which is basically a page transition between the "old" photo and the "new" photo.

Help!

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
function compileMessage(w){ // this is the function that assembles the HTML to display the photo and caption
displayMessage = "<img name=\"slideshow\" src=\"" + images[w].photo + "\" width=\"" + photoWidth + "\" height=\"" + photoHeight + "\" border=\"1\" alt=\"Photo © 2002 MacombSheriff.com - All rights reserved\" />";
if ((showNumbers)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-12-2002 06:01

I'm pretty sure it's because you are using the keyword "var" within a function.

I think if you use "var" inside a funtion then it is scoped only inside the function. So try

blah = 1;

I think what's happening is that because you are using var inside the function you are essentially setting 2 variables a global blah and another blah that is scoped only inside the function. So it's not that the global blah is getting reset to 0, instead the global var is never getting set to 1.




.:[ Never resist a perfect moment ]:.

[This message has been edited by bitdamaged (edited 08-12-2002).]

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-12-2002 06:16

Ah. Ok. That makes sense. I was wondering if it was something like that, or something like using global variables in PHP - just couldn't get it.

Well, that fixed THAT problem....

<runs off to find out why he's getting a 'null or not an object' error now....>

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-12-2002 07:04

that's usually a syntax error




.:[ Never resist a perfect moment ]:.

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 08-12-2002 11:50

on what line?


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-12-2002 15:07

Okay - first, the updated code:

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
function compileMessage(w){ // this is the function that assembles the HTML to display the photo and caption
displayMessage = "<img name=\"slideshow\" src=\"" + images[w].photo + "\" width=\"" + photoWidth + "\" height=\"" + photoHeight + "\" border=\"1\" alt=\"Photo © 2002 MacombSheriff.com - All rights reserved\" />";
if ((showNumbers)

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 08-12-2002 17:39

sorry, this is probably me being an idiot, but what is Play()?


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 08-12-2002 18:38

I thought transitions only worked on <DIV> but Im probably wrong, maybe that was only v.4 or something.
Or maybe its because its written to a layer and is therefore nested, try document.all in that line instead , give it a go anyway .. no harm.

mmh, thats a weird one , sorry I cant really help anymore.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-12-2002 21:02

Well, Play() actually causes the blend to execute. http://www.javascriptkit.com/howto/showie42.shtml

You can blend just about anything, not just DIVs. I do it directly to the <img>.....

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 08-13-2002 03:41

Is it case sensative?

I know most JS is so does play() and apply() work?



.:[ Never resist a perfect moment ]:.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 08-13-2002 06:05

I don't this it's a case issue, since I have a working script at http://development.runningwolf.com/code/javascript/slideshow.htm that uses the Apply() and Play() commands without a problem.

The theory is that you first define the transition time. In my case, it's 2 seconds. Then you use the Apply() to save the state of the first image, then assign the second image, then use Play() to actually do the transition from the first to the second. That part I'm pretty solid in. I'm just a little stuck on getting it to work with my dynamic slideshow. I'm not sure if I'm using it in the right place.....

« BackwardsOnwards »

Show Forum Drop Down Menu