copyrefer_0.wrl source
#VRML V2.0 utf8

Viewpoint {}
NavigationInfo {
type "EXAMINE"
}
Background {
skyColor 1 1 1
}

# 球
Transform {
translation -2 0 0
children [
Shape {
appearance Appearance {
material DEF Ball-Mt Material {
diffuseColor 1 0 0
}
}
geometry Sphere {}
}
DEF Ball-ThS TouchSensor {}
]
}
# 箱
Transform {
translation 2 0 0
children [
Shape {
appearance Appearance {
material DEF Box-Mt Material {
diffuseColor 1 1 0
}
}
geometry Box {}
}
DEF Box-ThS TouchSensor {}
]
}

# スクリプト
DEF Sc Script {
eventIn SFTime touched_Ball
eventIn SFTime touched_Box
eventOut SFColor ballColor
eventOut SFColor boxColor
field SFColor black 0 0 0
field SFColor red 1 0 0
field SFColor col 0 1 1
url "javascript:
function initialize () {

ballColor = red;

}
function touched_Ball () {

// c0 is reference of ballColor.
var c0 = ballColor;

var b = c0.b;
c0.b = c0.g;
c0.g = c0.r;
c0.r = b;

// c0 is reference of black.
c0 = black;

}
function touched_Box () {

// c1 is reference of col.
var c1 = col;

// boxColor is copy of c1.
boxColor = c1;

var b = c1.b;
c1.b = c1.g;
c1.g = c1.r;
c1.r = b;

print( 'boxColor = ' + boxColor );
print( 'col = ' + col );

}
"
}

ROUTE Ball-ThS.touchTime TO Sc.touched_Ball
ROUTE Box-ThS.touchTime TO Sc.touched_Box
ROUTE Sc.ballColor TO Ball-Mt.diffuseColor
ROUTE Sc.boxColor TO Box-Mt.diffuseColor