Thanks for all that but I finally managed to work it out! It would
seem that the variable of 's' was not being passed into the embedded
function in the GEvent.addListener. This meant that there was no
reference and truely 'rides[r]' was undefined as the r meant nohting
to it. Strangely though, when I made r a glocal variable it still
didn't work so I created a whole new variable called 't' and used that
just inside the embedded function and it worked a treat. I've included
the final code below for anyone else who may have this problem.
FYI...the url of the site is http://ucs.triforce.co.uk/trial2
-----CODE SNIPPET-----
//Global variables
var myrides = new Array(); //array of Gdirections objects.
var myroutes = new Array(); //array of latlng waypoints
var route_colour = new Array(); //array of colours
var t=0; //numeric variable for accessing array inside embedded
function of the GEvent.addListener
function init() {
~~~cutcode~~~
route_colour[0] = "#FF0000";
route_colour[1] = "#00FF00";
route_colour[2] = "#0000FF";
var j=0;
var k=1;
rtemax = rte_count-1;
for (j=0;j<=rtemax;j++) {
myroutes[j] = eval("route" + k);
k++;
}
imax = myroutes.length-1;
for (r=0;r<=imax;r++) {
myrides[r] = new GDirections();
}
for (s=0;s<=imax;s++) {
myrides[s].loadFromWaypoints(myroutes[s], {getPolyline: true});
GEvent.addListener(myrides[s], "load", function(){
var poly = myrides[t].getPolyline();
poly.color = route_colour[t];
poly.weight = "10";
poly.opacity = "0.5";
map.addOverlay(poly);
t++;
});
}
~~~cutcode~~~
}
-----CODE SNIPPET-----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---