OK, I confess at the outset I’m over my head a bit here.
I’ve had some code working fine. I created a global array variable z1=[]; and then stored ZeroClipboard objects in the array using the unique reference key r with the following code. (This may be evil in itself, but it worked.)
function zc(r){
var a="RP"+r,b="RDC"+r,c="RP"+r;
z1[r]=new ZeroClipboard.Client();
z1[r].addEventListener('mouseDown',function(client){z1[r].setText(document.getElementById(c).innerHTML);});
z1[r].addEventListener('complete',function(client,text){$('#'+a).aH("#D6EBFF",1000);});
z1[r].glue(a,b);}
I’ve recently realised how desperately wicked it is to have z1 as a global variable, so I’m trying to mend my ways and create an object to bound the whole business. But it’s not working…
I’ve done the following:
var zc={
z1: [],
add:function(r){
var a="RP"+r,b="RDC"+r,c="RP"+r;
z1[r]=new ZeroClipboard.Client();
z1[r].addEventListener('mouseDown',function(client){z1[r].setText(document.getElementById(c).innerHTML);});
z1[r].addEventListener('complete',function(client,text){$('#'+a).aH("#D6EBFF",1000);});
z1[r].glue(a,b);}
}
And I’m now calling zc.add(r) instead of zc(r) like before.
The Firebug error I’m getting is z1 is not defined. Why can my 'add' method not see my 'z1' property?
[Oh, and before someone asks why I don’t just put z1 in zc as it is, it’s because I access z1 from elsewhere in the code, and so I’m going to add further methods to the object.)
Change
z1[r]tothis.z1[r]I might also suggest setting it to a variable in the scope to avoid the lookups.