Closed Thread Icon

Topic awaiting preservation: I *know* it's null.. that's why I asked! (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8305" title="Pages that link to Topic awaiting preservation: I *know* it&amp;#039;s null.. that&amp;#039;s why I asked! (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: I *know* it&#039;s null.. that&#039;s why I asked! <span class="small">(Page 1 of 1)</span>\

 
Petskull
Maniac (V) Mad Scientist

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

posted posted 09-12-2002 07:50

I've I isolated the following problem:

code:
if (photoS[st2].src){
timer = setTimeout("blah(blah,st2)",50);
}



the problem is that if (photoS[st2].src) part...

I eventually get a 'photoS[...].src' is null or not an object error. I increment st2 and I expect that eventually photoS[st2].src will be null-- that's why the if() statement is there!

I'd like it to run thru the values and when 'photoS[st2].src' is null just don't run the if(). What am I doing wrong?


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

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-12-2002 09:19

try this:

if (photoS[st2] && photoS[st2].src){
timer = setTimeout("blah(blah,st2)",50);
}

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-12-2002 17:52

Yeah. See, you're allowed to check if something is undefined, but if you try to use an undefined thing as if it were an *object*, then the browser will complain.

So if

myobject is defined, but
myobject.myproperty is *not* defined, then

if (myobject) {...} will evaluate to true,
if (myobject.myproperty) {...} will evaluate to false, and
if (myobject.myproperty.anotherproperty) {...} will cause an error.

So you have to test each "level" down from the top level object, as lallous said.

If there's a chance that photos itself won't be defined, then you'll have to say:

if (photoS && photoS[st2] && photoS[st2].src) {...} // test each level down from the top, in descending order.

This ensures that each object is defined before you try to test its children.

BTW: did you mean to spell "photos" "photoS"? That might be the problem.

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-12-2002 20:48

ok, I tried it, and it didn't work...

I suspect that adding that fix just makes the if() true all the time because it just ends up crashing on the image change part the next time it rolls (seeing as photoS[ANY NUMBER NON-NEGATIVE NUMBER] will always be valid- that's what I think, anyway..)

I posted it here: http://www.twistedport.com/misc/test/imgani.html

*sigh* I am all outta ideas. I tried your ideas and even some funky shit I came up with, but nothing worked..

*head on over to jskit*


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

[This message has been edited by Petskull (edited 09-12-2002).]

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-12-2002 20:50

ok, new idea... maybe I should just code the upper and lower limits as global variables... it's ugly, though...

any other way?



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

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-12-2002 21:14

I'm not getting any errors. I don't see what's wrong. What is it doing wrong? What is it *supposed* to do?

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-13-2002 04:55

oh, my bad....

it's supposed to rollover three images- up and down- onmouseover (it's that image above 'Notes')

(I just added the images)

you get an error after the images reach the top...

...it's because of the 'if()' statement...


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

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-13-2002 05:58

Could you remove the alert boxes? I think they're making it behave differently for me so I'm not getting the error.

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-13-2002 07:31

there... sorry, I was testing..

Fuck, don't tell me this it just an IE6.0 bullshit...


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

[This message has been edited by Petskull (edited 09-13-2002).]

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-13-2002 10:05

hi PS,

if you apply the patch as i told you, you would avoid the first problem...but it seems you're not doing error checks in the rest of your code too!

when 'st2' (as an array index) is bigger than photoS.length you're getting this error!

you have this error at this line too:
document.images[set].src = photoS[start].src;
// window.status = set + start;
etc...

dunno what you're trying to do, but consider changing the method.

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-13-2002 14:49

yeah, I decided last night- in a fit of smokey rage- that what I'm going to do is just call one function, which would put the parameters into hard variables, and I'm just gonna use the values from the hard data for the 'aniup' function...

it's ugly, but it'll work...


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

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-13-2002 15:16

Hmm... still couldn't get an error =)

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-13-2002 16:04

Slime, you know how to reproduce the error?

I hovered over the image @ the bottom a couple of times so I get the error.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-13-2002 19:36

Oh, shoot, I forgot that ever since I installed VC++ it screws up error messages so I don't get them. Quite an annoyance. I used the workaround I've found and got the error =)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-13-2002 19:43

Petskull:

This should fix it. "Start" is eventually becoming equal to 2, which makes st2 equal to 3, and there is no third element in the array. If I understand your function right, you want to say

if (st2 < 3){

for the first if, and

if (st2 >= 0) {

for the second if.

In addition, inside the if(special == 'rev'), you don't want to use the st2 variable directly, since you know it's equal to 3. Instead, use st2-1:

timer = setTimeout("aniup(theset," + (st2-1) + ",endup,'dn',special)",50);

Actually, that line won't work at all. Remember that variables like special, endup, and theset are only defined within this function; when this function exits, and later the function you create with setTimeout is called, they won't exist anymore. So you must use:

timer = setTimeout("aniup("+theset+"," + (st2-1) + ","+endup?+",'dn',"+special+")",50);

Then it should, in theory, work.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-13-2002 19:46

Oh, one more thing. I see you using

if (...){...}
else {
if (...) {...}
}

Where you can just use

if (...) {...}
else if (...) {...}

They are actually the same thing, it's just that the second drops a pair of brackets that aren't necessary. However, lots of people tend to think of "if", "else if", and "else" as three separate things, which is also fine. Think of it however you want, you just don't need those brackets after the else =)

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-14-2002 03:32

yeah, I noticed that I was trying to use the dimentions of the array as the start-stop delimiter..

...then last night I think, "Why the fuck would I want to do that?"

I'm going to go with the plan of calling a function first to memorize all the initial parameters and THEN running the funtion with the timeout loop.

btw, I used those embedded 'if' statement because I forgot that 'else if' in Javascript was 'else if'- I'm still running off of the Perl convention of 'elsif'. When it didn't work, I just got rid of it and figured I'd ask later...




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

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-14-2002 05:42

ok, I got it working fine..

Now this is funny inquiry:

I have this line:

document.images[set].src = photoS[start].src;

now, I still want to use the array 'photoS[]', but I want to make it's name dynamic...

for example:

var myarray = "photoS"
document.images[set].src = myarray[start].src;


What's the way to do this? (I know that doesn't work... I tried it)


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

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-14-2002 06:00

got it with this..

eval("document.images[set].src = "+set+"S["+start+"].src;");

this the proper way?


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

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-14-2002 07:35

Ew, eval is ugly and slow. (Though heavily used for such things, so don't feel bad.) Make use of the window object:

var myarray = "photoS"
document.images[set].src = window[myarray][start].src;

the Window object is the "top level" object that contains all global variables and objects - including a reference to itself, which you can access via "window" or "self" as I did here. =)

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-14-2002 19:03

http://www.twistedport.com/misc/test/imgani.html

check it out now... it's almost done...
...all that's left is to dynamicize the framerate via an array...


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

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-15-2002 03:35

Great... now this line doesn't work...

superpic = initParam[0];
superset = initParam[1];
document.images[superpic].src = window[superset][0].src;

it's inside a function... is that a problem?


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

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-15-2002 08:00

Well, are superpic and superset defined either within the function or as global variables? If not, then they either need to be global variables (by saying var superpic, superset outside any functions), or they need to be passed to the function as arguments.

Making them global variables could cause issues (since they don't return to undefined every time the function they're defined in is called), so try passing them to the function.

Petskull
Maniac (V) Mad Scientist

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

posted posted 09-15-2002 09:10

I was stupid... I was using variables that I hadn't run yet...
I completed it.... lookie here:
http://www.ozoneasylum.com/Forum2/HTML/001773.html


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

« BackwardsOnwards »

Show Forum Drop Down Menu