When I was teaching 25 years ago, I wrote a program in Turbo Pascal to represent an on-screen microprocessor so that students could see their programs working. I am now trying to get these working on the web.
I've now got the CPU working slowly (although not fully tested). I now want the CPU to control the traffic lights.
see http://homepage.ntlworld.com/stoneba...ndtraffic3.htm
I have a parent page cpuandtraffic3.htm which is simply:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head><title>CPU and Traffic Lights</title>
</head>
<frameset cols="50%, 50%">
<frame src="cpu14.svg" align="top" name="cpudoc">
<frame src="traffic14.svg" align="top" name="trafficdoc">
</frameset>
</html>
My CPU fnlights() code is triggered by onclick on the 'L' button
function fnlights() {
var lite, attr
goslow=false;
var traffic = parent.document.getElementById('trafficdoc');
var doc = traffic.document;
lite = doc.getElementById("x1red");
attr = lite.getAttribute("fill");
if (attr == "red") { x1red.setAttribute("fill", "black"); }
else { x1red.setAttribute("fill", "red"); }
}
and I am trying to change the colour of the traffic light
<circle id="x1red" cx="175" cy="200" r="10" fill="red"/>
Thanks for any advice.
Opera reports
Event thread: click
Uncaught exception: TypeError: Cannot convert 'traffic' to object
Error thrown at line 780, column 0 in fnlights() in file://localhost/C:/Documents%20and%20Settings/Computer/My%20Documents/SVGexamples/cpu14.svg:
var doc = traffic.document;


Reply With Quote
Bookmarks