This is a collection of javascript and actionscript notes.
this is incomplete
These instructions assume you have a JavaScript capable web browser...
basic javascript/actionscript
...
strings: a series of quoted characters numbers: unquoted numeric values arrays: numbered lists objects: named lists boolean: true or falsevariables are created using the special word 'var' here is an example for each type of the basic types described above:
var mynumber = 0.2;
var mystring = 'hello world';
var myarray = [0, "a phrase", 9];
var myobject = {mynumber: 7, mystring: 'Lorum ipsum dolor.'};
var mytest = true;
now using the above variables in the following script fragments we get: alert(mynumber); alert: 0.2 alert(mystring); alert: hello world alert(myobject.mynumber); alert(myobject["mynumber"]); both do the same, alert: 7 alert(myarray[1]); alert: a phrase alert(mytest); alert: trueNote that mynumber that is attached to myobject is different from the other mynumber. Variables must start with a letter, _ or $; they cannot start with a number.
move on to JS Tutorial
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
} }
window.onload=function(){ alert('be vigilant!'); }
addLoadEvent(function(){alert('and alert!')});
addLoadEvent(function(){window.status='check check'});
add instructions to onload event (after the fact)
seems especially useful for changes to a (large) site after it is initially deployed
tinkering with detection of plugins.
looking @: IE5+; Safari 1+; Mozilla/Gecko/Firefox 1+; Opera 6+
see also:
http://www.quirksmode.org/js/flash.html
is it a good idea to look at the mimeTypes and have a handler flag (if hasRequired fails)?
function setup(def, child){
/*
def: {tag: 'div', attr: {name: value}}
{child}||'text'||number OR array of {child}/'text' }
*/
var d=document;
// create appropriate Element
if(typeof def != 'object') return d.createTextNode(def);
var el = (def.attr.id && d.getElementById(def.attr.id))? d.getElementById(def.attr.id) : d.createElement(def.tag);
if(typeof el == 'undefined') return false;
// attach Children through recursion
if(child){
if(child instanceof Array){ for(var i=0;i<child.length;i++){ el.appendChild( setup(child[i]) ); } }
else el.appendChild( setup(child) );
}
// set Attributes
for(var key in def.attr){
if(key == 'id') el.id = def.attr[key];
else if( (/class([Nn]ame){0,1}/).test(key) ) el.className = def.attr[key];
else if( key == 'style' ){
var styl = def.attr[key].split(';');
for(var i=0;i<styl.length;i++){
var r=styl[i].split(':');
el.style[r[0].replace(/[^a-z_\-]/gi,'')] = r[1];
}
}
else el.setAttribute(key, def.attr[key]);
}
// return Element
return el;
}
window.onload = function(){
document.body.appendChild( setup(
{tag: 'div',
attr:{id: 'test', classname: 'stuff', style: 'color:blue;background:#cf0'}},
'this is it.............'
));
var myjs = setup({tag:'script', attr:{id:'myjs', type: 'text/javascript', src: './test.js'}})
myjs.onload = function(){ alert('myjs HAS LOADED'); };
document.getElementsByTagName('head')[0].appendChild(myjs);
};
cross-site xhr: IE... Firefox (gecko clients) require enabling (in about:config) signed.applets.codebase_principal_support to true in Firefox 1.5 and Mozilla 1.7 a clear confirmation dialog advises of each xhr http://developer.mozilla.org/en/docs/AJAX:Getting_Started http://developer.mozilla.org/en/docs/Setting_HTTP_request_headers http://www.mozilla.org/projects/security/components/signed-scripts.html http://www.mozilla.org/projects/security/components/same-origin.html http://kb.mozillazine.org/XMLHttpRequest