example code not working

Michael Franklin <[email protected]> Fri, 22 Apr 2005 04:43:22 +0000 (UTC)
Newsgroups gmane.comp.windows.devel.netwindows
Message-ID <[email protected]>
Hi,

I have been trying to run the testComp() example from
...//netWindows/docs/manual.html#__components__ but it appears to be broken. 
The increment() function is never called.

Anyone got any ideas on what is wrong?

Thanks, Michael


<html>

<head>
<base fptype="TRUE">
<meta name=vs_targetSchema content="HTML 4.0">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>include test</title>

<!-- no netWindows objects are available up here -->
<script src="../../winScripts/netWindows.js"language="JavaScript"
type="text/javascript"></script>
<!-- all netWindows core objects 
(including __sig__) are now in scope -->
<script language="JavaScript" type="text/javascript" >

function testComp(){
  // we declare properties here just to be 
  // complete, this is not required in JavaScript
  this.domNode = null;
  this.textNode = null;
  this.counter = 0;

  // private initialization method 
  function init(){
    this.domNode = document.createElement("div");
    this.domNode.onclick = "__components__.getComponentFromNode(this).increment();";
    with(this.domNode.style){
      fontSize = "15px";
      fontFamily = "Arial, Helvetica, sans-serif";
      backgroundColor = "black";
      color = "white";
      width = "40px";
      height = "40px";
      textAlign = "center";
    }

    this.textNode = document.createTextNode(String(this.counter));
    this.domNode.appendChild(this.textNode);

    // add our visible representation to the page
	document.body.appendChild(this.domNode);
  }

  // public method called by event handler
  this.increment = function(){
    this.domNode.removeChild(this.textNode);
    this.textNode = document.createTextNode(String(this.counter++));
    this.domNode.appendChild(this.textNode);
  }

  // initialize the component
  init();
  // mixin-style inheritance:
  // used here to get every property of the parent class
  // but will not affect prototype chain
  NW_componentObj.call(this, this.domNode);
}

// prototype-style inheritance:
// unlike the mixin style, this ensures that 
// instanceof works correctly
testComp.prototype = new NW_componentObj();

__sig__.connectByName( __env__, "onLoad", null, "create");

function create() {
	// create some components
	var counter1 = new testComp();
	var counter2 = new testComp();
	// you can now click on the counters and they 
   // increment independently
}

</script>



</head>

<body >

</body>

</html>


_______________________________________________
The netWindows developers list: [email protected]
http://netwindows.org/mailman/listinfo/devel_netwindows.org