I have a map. On this map I have points, and when you click on these points it goes to a URL.
The code setup is as follows:
-
Arrays to define the movieclip
locations and another for the urls
(this one is an associative array). -
I then create a function loop to make
an event listener for each point.
When the point is clicked it will run
another function that handles the
URLs. -
The URL function is to grab the
target point that has been click, use
the url array type to find the key,
and then throw it in to the
URLRequest.
So far I have this code:
var places:Array = new Array();
places = [
map.paulsens, map.paraburdoo, map.plutonic, map.wiluna, map.gwalia, map.wallaby,
map.sunrise, map.moora, map.marvel, map.flyingFox, map.ernest, map.rosebery,
map.lyell, map.renison, kalMap.kanowna, kalMap.frogsLeg, kalMap.tindals,
kalMap.miitel, kalMap.higginsville
];
var links:Array = new Array();
links[ "paulsens" ] = "http://mywebsite.com/";
links[ "paraburdoo" ] = "http://mywebsite.com/";
links[ "plutonic" ] = "http://mywebsite.com/";
links[ "wiluna" ] = "http://mywebsite.com/";
links[ "gwalia" ] = "http://mywebsite.com/";
links[ "wallaby" ] = "http://mywebsite.com/";
links[ "sunrise" ] = "http://mywebsite.com/";
links[ "moora" ] = "http://mywebsite.com/";
links[ "marvel" ] = "http://mywebsite.com/";
links[ "flyingFox" ] = "http://mywebsite.com/";
links[ "ernest" ] = "http://mywebsite.com/";
links[ "rosebery" ] = "http://mywebsite.com/";
links[ "lyell" ] = "http://mywebsite.com/";
links[ "renision" ] = "http://mywebsite.com/";
links[ "kanowna" ] = "http://mywebsite.com/";
links[ "frogsLeg" ] = "http://mywebsite.com/";
links[ "tindals" ] = "http://mywebsite.com/";
links[ "miitel" ] = "http://mywebsite.com/";
links[ "higginsville" ] = "http://mywebsite.com/";
function listenerLoop():void {
var i:int;
for( i = 0; i < places.length; i++ ) {
( places[ i ] as IEventDispatcher ).addEventListener( MouseEvent.CLICK, openLink );
}
}
function openLink( event:MouseEvent ):void {
var link:URLRequest = new URLRequest( links[ event.target ] );
navigateToURL( link, "_blank" );
}
listenerLoop();
Now all works fine until I click on the point, giving me this error:
TypeError: Error #2007: Parameter url must be non-null.
at global/flash.net::navigateToURL()
at
navigateToURL( link, "_blank" );
It’s obvious to me that the openLink(); function isn’t doing what I want it to. I can kind of guess because event.target isn’t being turned in to a string or not pulling the array’s type?
try
and since you define strings for you iterator it may be better do define your links as an object in favor of an array