Jump to content

Graphic & Animation


L8V2L

Recommended Posts

You can get along quite well without ever using labels. In fact the "goto" mentality they inspire is rather questionable. I guess this is a little different though -- since the labels are limited to only identifying loops or code blocks.

 

When are you going to write some of your own code? Demonstrate some group of features? Create a simple game?

Link to comment
Share on other sites

You can get along quite well without ever using labels. In fact the "goto" mentality they inspire is rather questionable.

when you say "GOTO MENTAITLIY" you are referring to label as that what they do? they reference to a object/function/variable/control structure <~~~ is this correct? Just like to have clarity. Please answer with an yes or no, following your input.

When are you going to write some of your own code? Demonstrate some group of features? Create a simple game?

As I study, I can see the code of what I want to do, first it was visual, now I think about what I want to happen and what I want it to look like, and it comes as code.... I need to study more, II'm in the process of going through js+json+ajax, html, js+json+ajax, css, js+json+ajax and the whole section of xml between subjection, I'll go back through js+json+ajax... and read a couple of books. Then after that, if I feel like a wizard, or less like a hack, then I'll start writing it. I'm currently finishing my second going through of js and about to head to json... or through the reference of js, might do that every other trip... but really I'm finish the third time through the tutorial of it.I', doing xml to have more of an understanding for svg.(and recently learn of smil , which is just svg animation plus more) Edited by L8V2L
Link to comment
Share on other sites

Historically the GOTO statement is considered a major cause of some very confusing and essentially unmaintainable code.

 

http://en.wikipedia.org/wiki/Go_To_Statement_Considered_Harmful#Criticism_and_decline

 

You should not plan to write a large program until you have written many small programs. For example if you plan to use JSON and AJAX in a project then first write a small program that simply tests JSON and AJAX. If you write the functions well then you will be able to re-use them later in your larger program.

Link to comment
Share on other sites

the problem is you aren't writing. no amount of reading, especially spread out over so many topics, is a substitute for just doing.

Link to comment
Share on other sites

the section tag/element/node alter thee element/tag/nodes it contain. It change the size of the header tag, so it's safe to say that it alter the rest of the tag, even if you can't tell the different.

Edited by L8V2L
Link to comment
Share on other sites

<!DOCTYPE html><html><head><script>function toggle0() { //I was defeated by this yester... early in the morning before I went to bed. var p = document.getElementById("demo");var txt = p.innerHTML;var button = p.previousElementSibling; button.onclick=myFunc;// <--require: JS attach event handler.function myFunc(){p.innerHTML=(p.innerHTML == txt)?("Hello JavaScript"):(txt);}}window.onload = toggle0;</script></head><body><h1>My First JavaScript</h1><p>JavaScript can change the content of an HTML element:</p><button type="button">Click Me!</button><p id="demo">This is a demonstration.</p></body></html><!DOCTYPE html><html><head><script>function toggle0() { //I was defeated by this yester... this earlier morning before I went to bed. //get id=demo, set in var p, attach event handler var p = document.getElementById("demo");var txt = p.innerHTML;var button = p.previousElementSibling; button.onclick=myFunc; //set toggle functionfunction myFunc(){p.innerHTML=(p.innerHTML == txt)?("Hello JavaScript"):(txt);}}window.onload = toggle0;</script></head><body><h1>My First JavaScript</h1><p>JavaScript can change the content of an HTML element:</p><!--can't set the attribute onclick, won't work--><button type="button" onclick="myFunc()">reconstruct the problem</button></button><p id="demo">This is a demonstration.</p></body></html>
Link to comment
Share on other sites

Try this basis...

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>Demo01</title><style>#demo{color:#9f9}</style><script>var txt; //globalfunction init() { var button = document.getElementById("btn1");button.onclick = toggletxt;txt = document.getElementById("demo").innerHTML;}//end of init functionfunction toggletxt(){var p = document.getElementById("demo");p.innerHTML=(p.innerHTML == txt)?("Hello JavaScript"):(txt);}//end of functionwindow.onload = init;</script></head><body><h1>My First JavaScript</h1><p>JavaScript can change the content of an HTML element:</p><button id="btn1">Click Me!</button><p id="demo">This is a demonstration.</p><p>Try to give variables and functions meaningful names.</p><p>Don't try to walk the DOM without considering text and comment nodes.</p></body></html>
Link to comment
Share on other sites

Labelled statements are only used in conjunction with labelled break and continue statements. ECMAScript has no goto statement.reference from ECMAscript...control structure... could be call a control structure expression??? control structure statement... But as he said, control structure... a new <~~~~ technic for me.... but as stated, not usefully... but still a technique that could be use... keep in mind... control strucute.... control structure..can some one give me an example of the with statement?

Link to comment
Share on other sites

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>Demo01</title><style>#demo{color:#9f9}</style><script>var txt; //global//init function set/get data needed after onload event take placefunction init() { var button = document.getElementById("btn1");button.onclick = toggletxt;txt = document.getElementById("demo").innerHTML;}//end of init function//learnt: can have function out side of init functionfunction toggletxt(){var p = document.getElementById("demo");p.innerHTML=(p.innerHTML == txt)?("Hello JavaScript"):(txt);}//end of functionwindow.onload = init;</script></head><body><h1>My First JavaScript</h1><p>JavaScript can change the content of an HTML element:</p><!--Original problem: Could not set toggletext in element i.e: onclick="toggletext()";--><button type="button"; onclick="toggletext()";>Click Me!</button><!--Unless the actually code is set underneath the button element/node/tag--><!--<button id="btn1">Click Me!</button>--><p id="demo">This is a demonstration.</p><p>Try to give variables and functions meaningful names.</p><p>Don't try to walk the DOM without considering text and comment nodes.</p></body></html>
Edited by L8V2L
Link to comment
Share on other sites

How to trigger two function in an statement; refer two both, the for statement out side the closure functions and the switch statement:

<!DOCTYPE html><html><body><p id="demo"></p><script>var txt="ABCDEFGHIJKLMNOPQRSTUVWXYZ", str = "", i = 0, txtLength = txt.length, p = document.getElementById("demo");fo:function funcFor(){for(i, txtLength; i < txtLength; i++){p.innerHTML+=txt[i].toLowerCase();}}whil:function funcWhile(){while(i < txtLength){document.getElementById("demo").innerHTML += txt[i];i++;}}if(0<1){//whil://funcFor() /*with(*/eval(funcWhile()&&funFor());/*); funcFor();*/}/*switch(0){case 0 : {funcFor();funcWhile();//break;}case 1:{funcWhile();break;}}*/</script></body></html>
Edited by L8V2L
Link to comment
Share on other sites

For now I would suggest that you don't use labels. Don't use eval. Don't use with.

 

And don't use closures unless you can explain WHY you are using them.

Link to comment
Share on other sites

For now I would suggest that you don't use labels. Don't use eval. Don't use with. And don't use closures unless you can explain WHY you are using them.

:( Could you please honor(forgot the other word... fulfill) my request. :( Edited by L8V2L
Link to comment
Share on other sites

Why doesn't this work!!!!?????

<!DOCTYPE html><html><head><script>function fin(){function myFunction(){document.getElementById("myDiv").innerHTML="njinnjknj";}}window.onload = fin;</script></head><body><div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="myFunction()">Change Content</button></body></html>
Edited by L8V2L
Link to comment
Share on other sites

What is the point of it? The function fin() is still sitting there in the global space.

for the onload event.it should work. Why won't it work and show me how to make it work please. Edited by L8V2L
Link to comment
Share on other sites

<!DOCTYPE html><html><head><script>window.onload = function(){var cnt = 0;function changeh2(){document.getElementById('myh2').innerHTML='success success success, cnt=' + cnt++;}document.getElementById('btn1').onclick = changeh2;}</script></head><body><div><h2 id="myh2">Let's change this text</h2></div><button type="button" id="btn1">Change Content</button></body></html>
Link to comment
Share on other sites

<!DOCTYPE html><html><head><script>window.onload = function(){var cnt = 0;function changeh2(){document.getElementById('myh2').innerHTML='success success success, cnt=' + cnt++;}//document.getElementById('btn1').onclick = changeh2;//invoke onclick in the button element/node/tag itself. not in the script tag.}</script></head><body><div><h2 id="myh2">Let's change this text</h2></div><button type="button" id="btn1" onclick="changeh2()">Change Content</button></body></html>
Edited by L8V2L
Link to comment
Share on other sites

 

//invoke onclick in the button element/node/tag itself. not in the script tag.

 

 

Go ahead. Try. It just proves that you don't know what you're doing.

Link to comment
Share on other sites

Go ahead. Try. It just proves that you don't know what you're doing.

... I'm ask this question a while back, and did not get no answer. I'm asking why not? Why do I have to define the onclick event in JavaScript? Why can't it be done in the start tag/node/element itself? Why?JAVASCRIPT SERVER SIDE SCRIPTING!!!!!!!!!!!!!!!!!! Edited by L8V2L
Link to comment
Share on other sites

The whole point of using a closure is to avoid using the global space. If you are going to use the global space THEN YOU DON'T NEED A CLOSURE.

.... No.. I want the onclick to work with out sitting it in JavaScript. I need to have it in a function to be onloaded when the document finishing loading so it can work, but it work out side the function onload... I don't understand why, and don't really feel secure if I wrote code in an external file that it'll function as so. Edited by L8V2L
Link to comment
Share on other sites

A ) Its actually better to keep HTML and Javascript as separate as possible. Its one of those things about having lower coupling (less things you have to connect via static code). using more and more inline javascript means that if you change the function name, or you need to write a new html element, you'll be writing and changing more and more code in the end. There is no practical reason why you should write javascript inside the HTML instead in the script tag.

 

B ) Closures implies providing implicit access of one scope while in another and that is most often accomplished by using "return". In any event you need to provide some sort of way to bridge the 2 scopes together. without using return you have to do something like in this jsfiddle, where I initialize the identifier for the function in the global space... but I wait to actually define it inside the onload. So while the function exists in the global scope, it was defined in another scope. thus it knows about and can access the "cnt" variable despite being a global function.

 

C ) Dave's code is actually valid and it works from what I can see. you are likely misinterpreting his code. Remember to format your code. use indents. every time you make curly braces. all that extra white space may seem wasteful or may make your code appear lacking in content, but it really helps everyone in finding the problem and the extra white space actually encourages people to actually read it. I've said this before. And you can clearly see where one code block begins and another ends. Plus in the end you can use a minifier to actually compress your code into a nice, tiny, space-efficient block of algorithm (just remember to keep a human-readable copy).

 

I believe this is likely what is confusing you here as you seem to think the onclick handler was assigned outside the onload handler, when it isn't.

 

  • Like 1
Link to comment
Share on other sites

<!DOCTYPE html><html> <head>  <script>   var changeh1;   function init() {     var cnt=0;      //YES! This is what I wanted... similar to it!     changeh1 = function(){ /*<~~Why fail as "function changeh1()"?*/        document.querySelector("p").innerHTML="success cnt="+(++cnt);     }   }   window.onload = init;  /*To JSG, I TOLD YOU THERE IS AWAY TO DO THE COUNT EXAMPLE LIKE THIS! JA~VA~SCRIPT!!!*/  </script> </head> <body>  <h1>My First JavaScript</h1>  <button type="button" onclick="changeh1()">click me</button>  <h1></h1>  <p></p> </body></html> 
...Davej got frustrated-ly mad at me.... even yield at me. Edited by L8V2L
Link to comment
Share on other sites

You can simply establish a namespace, and use it, or you can use a closure to establish a namespace and have private static variables and private functions. Why do you need private static variables and private functions? Tell me. Explain it.

Link to comment
Share on other sites

Why doesn't this work!!!!?????

<!DOCTYPE html><html><head><script>function fin(){function myFunction(){document.getElementById("myDiv").innerHTML="njinnjknj";}}window.onload = fin;</script></head><body><div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="myFunction()">Change Content</button></body></html>

because myFunction is defined inside fin. Why do you have the function wrapped in another function? What is the point?

 

If you had your developer tools and console open, you would see a function not defined error.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...