davelk
September 30th, 2008, 03:35 PM
Hi, I am making a map with tooltips that are triggered by invisible movieclips sitting on top of each continent.
I know I could do this by referencing each instance and giving it it's own event listener but I'm trying to learn how to do things more dynamically.
heres the code so far...I need a variable that holds a string for the country I currently have the mouse over. Then I can obviously use that variable to send the right text to the textfield within my tooltip movieclip.
Thanks in advance guys, please talk to me like an I'm stupid and I'll stand a better chance of understanding you
//hide tooltip
toolTip.visible = false;
//make tooltip follow cursor
addEventListener(Event.ENTER_FRAME, followCursor);
function followCursor(e:Event):void
{
toolTip.x = mouseX;
toolTip.y = mouseY;
}
//create array to hold transparent movieclips/hit areas
var countries:Array = new Array();
countries.push(africa);
countries.push(asia);
countries.push(europe);
countries.push(oceania);
countries.push(northAmerica);
countries.push(southAmerica);
//----This was a test to see if I could convert the instance name of an mc to string
//----but the textfield just displays '[object movieclip]'
var currentCountry:String = countries[0].toString();
function doRollOver(e:MouseEvent):void{
toolTip.visible = true;
toolTip.toolText.text = currentCountry;
}
function doRollOut(e:MouseEvent):void{
toolTip.visible = false;
}
//assign listeners to each movieclip in the countries array
function init():void
{
var i=0;
var hitArea;
for (i=0; i<countries.length; i++){
area = countries[i];
area.addEventListener(MouseEvent.MOUSE_OVER, doRollOver);
area.addEventListener(MouseEvent.MOUSE_OUT, doRollOut);
//area.addEventListener(MouseEvent.MOUSE_OVER, doClick);
}
}
init();
I know I could do this by referencing each instance and giving it it's own event listener but I'm trying to learn how to do things more dynamically.
heres the code so far...I need a variable that holds a string for the country I currently have the mouse over. Then I can obviously use that variable to send the right text to the textfield within my tooltip movieclip.
Thanks in advance guys, please talk to me like an I'm stupid and I'll stand a better chance of understanding you
//hide tooltip
toolTip.visible = false;
//make tooltip follow cursor
addEventListener(Event.ENTER_FRAME, followCursor);
function followCursor(e:Event):void
{
toolTip.x = mouseX;
toolTip.y = mouseY;
}
//create array to hold transparent movieclips/hit areas
var countries:Array = new Array();
countries.push(africa);
countries.push(asia);
countries.push(europe);
countries.push(oceania);
countries.push(northAmerica);
countries.push(southAmerica);
//----This was a test to see if I could convert the instance name of an mc to string
//----but the textfield just displays '[object movieclip]'
var currentCountry:String = countries[0].toString();
function doRollOver(e:MouseEvent):void{
toolTip.visible = true;
toolTip.toolText.text = currentCountry;
}
function doRollOut(e:MouseEvent):void{
toolTip.visible = false;
}
//assign listeners to each movieclip in the countries array
function init():void
{
var i=0;
var hitArea;
for (i=0; i<countries.length; i++){
area = countries[i];
area.addEventListener(MouseEvent.MOUSE_OVER, doRollOver);
area.addEventListener(MouseEvent.MOUSE_OUT, doRollOut);
//area.addEventListener(MouseEvent.MOUSE_OVER, doClick);
}
}
init();