...

View Full Version : Why isn't my event observer working? (ptototype)



Sleeping_Troll
05-28-2009, 10:14 PM
This is my script:

Event.observe(
'Orb'+i,
'mouseover',
function(event) {
Orb[i].Img.static=1;
alert("hello");
});
Event.observe(
'Orb'+i,
'mouseout',
function(event) {
Orb[i].Img.static=0;
alert("hello");
});

xzzy (nothing happens!)
Why?
If you need more code I will provide!
I am at "That" point, all I can do is sit and stare!

itsallkizza
05-28-2009, 10:38 PM
Post the relevant html elements and JS.

Sleeping_Troll
05-28-2009, 11:53 PM
html

<link rel="stylesheet" href="CSS/style.css" type="text/css">
<style type="text/css">
<!--
.style1 {font-size: xx-large}
-->
</style>
</head>
<body onLoad="init()" onResize="resize()">
<div id="content">
<div id="banner"><img src="images/Bnnr.png" name="bannerImage" id="bannerImage"></div>
<td><div id="container"></div></td>
<div id="FilterBox" align="center">
<form name="Filter" method="get" action="/search.html">
<label>
Filter Term
<input type="text" name="q" class="text">
</label>
<input type="submit" name="Submit" value="Apply filter" class="text">
</form>
</div>
</div>

<!--end of contentArea-->
</body>
<embed hidden="true" src="sounds/warpedspace.mp3" pluginspage="http://www.macromedia.com/shockwave/download/" autostart="true" width="32" height="32"></embed>
</html>
css

html{
}
body{
}
#content {
position: absolute;
left: 0px;
top: 0px;
border: 0;
margin: 0;
background-color: #6600FF;
height: 800px;
width: 100%;
}
#content #banner {
background-color: #CCCCCC;
position: relative;
left: 0px;
top: 0px;
border: 0;
margin: 0;
}
#content #Menu {
background-color: #FFFF00;
position: relative;
float:left;
border: 0;
margin: 0;
}
#content #container{
z-index: -10000;
background-color:#000000;
position: relative;
float: left;
overflow: hidden;
width: 60%;
border: 0;
margin: 0;
}
#content #container img{
position: absolute;
border: 0;
margin: 0;
}
}
#content #FilterBox {
position: absolute;
}
script

////////////////////////////////////////////
// Thanks to the inspiration of thwacks! //
// evolve 14/06/2004 //
// http://www.mgifos.demon.co.uk //
// last evolved 15/06/2004 //
////////////////////////////////////////////
var numOrbs=12; //number of Orbs
var InitialVelocity;
var Zeye; //perspective:distance of eye from box centre
var Zscreen; //perspective:distance of screen from box centre
var OrbBaseRadius
var OrbProximityFactor;
var Xmin,Ymin,Xmax,Ymax,Zmin,Zmax;
var Perspective;
var Dimensions=[];
var Orb=[];

function init(){
for(i=0;i<numOrbs;i++){
Orb[i]=[];
Orb[i].Img=new Element("img",{id:"orb"+i, src:"./images/Orb.png", style:"display=none"});
$("container").insert(Orb[i].Img);
Orb[i].Img.static=0
resize();
var theta;
Orb[i].PositionX=Xmax/2;
Orb[i].PositionY=Ymax/2;
Orb[i].PositionZ=Zmax*.0001;
theta=Math.PI*2*Math.random();
phi=Math.asin(Math.random());
if(Math.random()>0.5)phi=-phi;
Orb[i].VelocityX=InitialVelocity*Math.sin(theta)*Math.cos(phi);
theta=Math.PI*2*Math.random();
phi=Math.asin(Math.random());
if(Math.random()>0.5)phi=-phi;
Orb[i].VelocityY=InitialVelocity*Math.cos(theta)*Math.cos(phi);
theta=Math.PI*2*Math.random();
phi=Math.asin(Math.random());
if(Math.random()>0.5)phi=-phi;
Orb[i].VelocityZ=InitialVelocity*Math.cos(phi);
Orb[i].renew=0;
Event.observe(
'Orb'+i,
'mouseover',
function(event) {
Orb[i].static=1;
alert("hello");
});
Event.observe(
'Orb'+i,
'mouseout',
function(event) {
Orb[i].static=0;
alert("hello");
});
}
setInterval("collisions()",50);
}
function Static(){
alert(Orb[i].static);
}

function collisions(){
/////////////////////////////////////////////////////////////
// Collision math
// Based on the fluid simulation by Peter Birtles //
// http://astronomy.swin.edu.au/pbourke/modelling/fluid/ //
// //
// Javascript conversion evolved January 2002 //
// 3D conversion and "energy leak" plugged 10/06/2004 //
/////////////////////////////////////////////////////////////
var i,q,Proximity,VelocityXa,VelocityYa,VelocityZa,VelocityXb,VelocityYb,VelocityZb,Xdisplacement,Ydispl acement,Zdisplacement,Xvector,Yvector,Zvector,m,ResultantTotal,Xresultant,Yresultant,Zresultant;
for(i=0;i<numOrbs;i++){
Perspective=(Zeye-Zscreen)/(Zeye+Orb[i].PositionZ);
Orb[i].size=OrbBaseRadius*Perspective;
OrbProximityFactor=4*Orb[i].size*Orb[i].size;
for(q=(i+1); q<numOrbs; q++){ //Note:The original iterated both a and b from 1 to numOrbs, skipping the a=b case
Proximity = (Orb[i].PositionX-Orb[q].PositionX)*(Orb[i].PositionX-Orb[q].PositionX)+(Orb[i].PositionY-Orb[q].PositionY)*(Orb[i].PositionY-Orb[q].PositionY)+(Orb[i].PositionZ-Orb[q].PositionZ)*(Orb[i].PositionZ-Orb[q].PositionZ);
if (Proximity < OrbProximityFactor){
Proximity = Math.sqrt(Proximity);
VelocityXi= Orb[i].VelocityX;VelocityYi=Orb[i].VelocityY;VelocityZi=Orb[i].VelocityZ;VelocityXq=Orb[q].VelocityX;VelocityYq=Orb[q].VelocityY;VelocityZq=Orb[q].VelocityZ;
Xdisplacement=Orb[q].PositionX-Orb[i].PositionX;
Ydisplacement=Orb[q].PositionY-Orb[i].PositionY;
Zdisplacement=Orb[q].PositionZ-Orb[i].PositionZ;
if (Math.abs(Proximity)>0.0001){
Xvector=Xdisplacement/Proximity;Yvector=Ydisplacement/Proximity;Zvector=Zdisplacement/Proximity;
m = Math.sqrt(VelocityXi*VelocityXi+VelocityYi*VelocityYi+VelocityZi*VelocityZi);
if (Math.abs(m)>0.0001){
TotalResultant = (Xvector*VelocityXi+Yvector*VelocityYi+Zvector*VelocityZi);
Xresultant=TotalResultant*Xvector;
Yresultant=TotalResultant*Yvector;
Zresultant=TotalResultant*Zvector;
VelocityXi -= Xresultant;
VelocityYi -= Yresultant;
VelocityZi -= Zresultant;
VelocityXq += Xresultant;
VelocityYq += Yresultant;
VelocityZq += Zresultant;
}
m = Math.sqrt(Orb[q].VelocityX*Orb[q].VelocityX+Orb[q].VelocityY*Orb[q].VelocityY+Orb[q].VelocityZ*Orb[q].VelocityZ);
if (Math.abs(m) >0.0001){
TotalResultant = (Xvector*Orb[q].VelocityX+Yvector*Orb[q].VelocityY+Zvector*Orb[q].VelocityZ);
Xresultant=TotalResultant*Xvector;
Yresultant=TotalResultant*Yvector;
Zresultant=TotalResultant*Zvector;
VelocityXi += Xresultant;
VelocityYi += Yresultant;
VelocityZi += Zresultant;
VelocityXq -= Xresultant;
VelocityYq -= Yresultant;
VelocityZq -= Zresultant;
}
Orb[i].VelocityX=VelocityXi;Orb[i].VelocityY=VelocityYi;Orb[i].VelocityZ=VelocityZi;Orb[q].VelocityX=VelocityXq;Orb[q].VelocityY=VelocityYq;Orb[q].VelocityZ=VelocityZq;
}
}
}
}
moveOrbs();
}

function moveOrbs(){
for(i=0;i<numOrbs;i++){
if(Orb[i].Img.static==0){
Orb[i].PositionX += Orb[i].VelocityX;
Orb[i].PositionY += Orb[i].VelocityY;
Orb[i].PositionZ += Orb[i].VelocityZ;
Perspective=(Zeye-Zscreen)/(Zeye-Orb[i].PositionZ);
Orb[i].size=Math.round(OrbBaseRadius*Perspective);
Orb[i].Img.style.zIndex=Orb[i].PositionZ;
Orb[i].Img.style.display='block';
if (Orb[i].PositionX<Xmin-(Orb[i].size)){
if(Orb[i].renew==1){
Orb[i].renew=2;
}
Orb[i].PositionX=Xmax+Orb[i].size;//wrap
}
if (Orb[i].PositionX>Xmax+(Orb[i].size)){
if(Orb[i].renew==1){
Orb[i].renew=2;
}
Orb[i].PositionX=Xmin-Orb[i].size;//wrap
}
if (Orb[i].PositionY<Ymin-(Orb[i].size)){
if(Orb[i].renew==1){
Orb[i].renew=2;
}
Orb[i].PositionY=Ymax+Orb[i].size;//wrap
}
if (Orb[i].PositionY>Ymax+(Orb[i].size)){
if(Orb[i].renew==1){
Orb[i].renew=2;
}
Orb[i].PositionY=Ymin-Orb[i].size;//wrap
}
if (Orb[i].PositionZ<Zmin&&Orb[i].VelocityZ<0){
Orb[i].VelocityZ=-Orb[i].VelocityZ;//rebound
}
if (Orb[i].PositionZ>Zmax&&Orb[i].VelocityZ>0){
Orb[i].VelocityZ=-Orb[i].VelocityZ;//rebound
if(Orb[i].renew==0)Orb[i].renew=1;
}
if (Orb[i].renew==2){
Orb[i].Img.src="./images/NewImage.png";
Orb[i].renew=0;
}
Orb[i].Img.style.left=Orb[i].PositionX-Orb[i].size+'px';
Orb[i].Img.style.top=Orb[i].PositionY-Orb[i].size+'px';
Orb[i].Img.style.width=Orb[i].size*2+'px';
Orb[i].Img.style.height=Orb[i].size*2+'px';
}
Orb[i].Img.stopObserving();
}
}

function resize(){
if (window.innerWidth){ //if browser supports window.innerWidth
Dimensions.width=window.innerWidth;
Dimensions.height=window.innerHeight;
}
else if (document.all){ //else if browser supports document.all (IE 4+)
Dimensions.width=document.body.clientWidth;
Dimensions.height=document.body.clientHeight;
}
Zmax=Dimensions.width*2;
$("banner").style.width=Dimensions.width
Xmax=Dimensions.width*.6;
Ymax=Xmax*.75;
$("container").style.width=Xmax;
$("container").style.height=Ymax;
$("container").style.left=Dimensions.width*.1
$("container").style.top=20
$("FilterBox").style.top=Ymax+120
OrbBaseRadius=Xmax/50;
Xmin=0;
Ymin=0;
Zmin=0;
Zscreen=Zmax*.25;
Zeye=Zmax*1.1;
InitialVelocity=Dimensions.width/Xmax*4;
}

Sleeping_Troll
05-28-2009, 11:59 PM
Also! http://huduzu.trollnest.com

Sleeping_Troll
05-29-2009, 12:05 AM
Hmmm... something interesting! I posted the site to my host, so you could peruse it, I have onresize resetting all the elements, however if you shrink the window to quickly it crashes the script... and guess what? Then the observer works! Now how to get around that little jewel...

Sleeping_Troll
05-29-2009, 12:10 AM
Also, something about this problem is keeping the site from working in firefox. Perhaps the "registry undefined" error will give you a clue?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum