•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 423,681 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,224 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3327 | Replies: 1
![]() |
•
•
Join Date: Feb 2007
Posts: 56
Reputation:
Rep Power: 2
Solved Threads: 0
Hello, I get an error message saying flow() is not defined when I debug in firebug. I am not sure why this is happening. Here is my code:
javascript Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Image Flow</title> <script type="text/javascript"> function imageFlow() { var R = 0; var x1 = .1; var y1 = .05; var x2 = .25; var y2 = .24; var x3 = 1.6; var y3 = .24; var x4 = 300; var y4 = 200; var x5 = 300; var y5 = 200; DI = document.images; DIL = DI.length; function flow() { for(var i = 0; i < DIL; i++) { DIS = DI[i].style; DIS.position = 'absolute'; DIS.left = Math.sin(R * x1+ i * x2 + x3) * x4 + x5; DIS.top = Math.cos(R * y1 + i * y2 + y3) * y4 + y5; } R++; } setInterval("flow()", 5); void(0); } </script> </head> <body onload = imageFlow()> <p><img alt="Nature1" src="img1.jpg" /></p> <p><img alt="Nature2" src="img2.jpg" /></p> </body> </html>
Last edited by adaykin : Dec 23rd, 2007 at 8:18 pm.
My Website <-- check out my site!
This is because Javascript searches for 'flow()' in the global scope but it so happens that your declaration of flow being present in the function imageFlow is not visible / is not a property of the global object. This can also be attributed to the fact that setTimeout and setInterval always search the global scope.
You can avoid this in many ways, two of which are: Either set this function flow as the property of your function imageFlow or use closures / anonymous functions.
The second one is definitely a better way since calling setInterval() with a string equivalent of javascript (as in the first one) fires of an instance of interpreter to convert the string to actual javascript code, something not recommended since it is pretty expensive performance wise.
You can avoid this in many ways, two of which are: Either set this function flow as the property of your function imageFlow or use closures / anonymous functions.
javascript Syntax (Toggle Plain Text)
/* Setting the property of imageFlow function */ function imageFlow() { var R = 0, x1 = .1, y1 = .05, x2 = .25, y2 = .24, x3 = 1.6, y3 = .24, x4 = 300, y4 = 200, x5 = 300, y5 = 200; var DI = document.images, DIL = DI.length; var flow = function() { for(var i = 0; i < DIL; i++) { DIS = DI[i].style; DIS.position = 'absolute'; DIS.left = Math.sin(R * x1+ i * x2 + x3) * x4 + x5; DIS.top = Math.cos(R * y1 + i * y2 + y3) * y4 + y5; } R++; } imageFlow['flow'] = flow; setTimeout("imageFlow.flow()", 100); } window.onload = imageFlow;
javascript Syntax (Toggle Plain Text)
function imageFlow() { var R = 0, x1 = .1, y1 = .05, x2 = .25, y2 = .24, x3 = 1.6, y3 = .24, x4 = 300, y4 = 200, x5 = 300, y5 = 200; var DI = document.images, DIL = DI.length; var flow = function() { for(var i = 0; i < DIL; i++) { DIS = DI[i].style; DIS.position = 'absolute'; DIS.left = Math.sin(R * x1+ i * x2 + x3) * x4 + x5; DIS.top = Math.cos(R * y1 + i * y2 + y3) * y4 + y5; } R++; } setTimeout(function() { flow(); }, 1000); } window.onload = imageFlow;
The second one is definitely a better way since calling setInterval() with a string equivalent of javascript (as in the first one) fires of an instance of interpreter to convert the string to actual javascript code, something not recommended since it is pretty expensive performance wise.
Last edited by ~s.o.s~ : Dec 24th, 2007 at 12:25 am.
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp cross-browser javascript menu with few lines of code developer development firefox home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator microsoft msdn office prevent javascript menu from getting hidden under flash movies site software sql vista web
- C a function to uppercase a string (C)
- undefined offset ERROR! (PHP)
- Image Resize Function Error (PHP)
- Linker Error>Undefined reference error to xyz (C++)
- function declaration in MatLab (Legacy and Other Languages)
- WriteFile() function in printf() freezes (C)
- undefined reference errors when using C++ Sockets Library (C++)
- Print_Zero Function (C)
- object undefined instead of string literal (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Help with code change if possible
- Next Thread: iframe Height adjustment to loaded content, help please?



Linear Mode