Re: example code not working - fixed -manual needs updating

Michael Franklin <[email protected]> Tue, 26 Apr 2005 03:58:56 +0000 (UTC)
Newsgroups gmane.comp.windows.devel.netwindows
Message-ID <[email protected]>
Hi,

The example code that follows the testComp() example is better structured. 
Applying that structure to the testComp() code fixes the problem.  

Is anyone actively maintaining the documentation?  The textComp() example code
should be rewritten.  Below is the version I ended up with

Michael

<html>

<head>
<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>component test</title>

<!-- no netWindows objects are available up here -->
<script src="../../winScripts_no_docs/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( colour ){
  // we declare properties here just to be 
  // complete, this is not required in JavaScript
  this.domNode = null;
  this.textNode = null;
  this.counter = 0;

  this.domNode = document.createElement("div");
  __sig__.connectByName( this.domNode, 'onclick', this, 'increment' );
  
  with(this.domNode.style){
    fontSize = "15px";
    fontFamily = "Arial, Helvetica, sans-serif";
    backgroundColor = colour;
    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);

  // 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();

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

// override the class-level properties from NW_componentObj
testComp.prototype.componentType = "testComp";
testComp.prototype.isTopLevel = false;
    
__sig__.connectByName( __env__, "onLoad", null, "create");

function create() {
	// create some components
    var counter1 = new testComp( 'blue' );
    var counter2 = new testComp( 'green' );
	// 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