网上有些例子不是不完善就是pay money的.自已整蛊了个.
部分代码:
/**/
/*------------------------------------------------*/
stop();
tipBord.visible = false ;
mapBord.addEventListener(MouseEvent.MOUSE_MOVE,mapMove);
mapBord.map.addEventListener(MouseEvent.MOUSE_OVER,mapHit);
mapBord.map.addEventListener(MouseEvent.MOUSE_OUT,mapOut);
mapBord.textBord.addEventListener(MouseEvent.MOUSE_OVER,visibleTip);
mapBord.map.addEventListener(MouseEvent.CLICK,openURL);
tipBord.addEventListener(MouseEvent.MOUSE_OVER,visibleTip);
// 鼠标点击事件
function openURL(event:MouseEvent): void {
var url:String = returnURL(event.target.name);
if(url.length > 4)
{
navigateToURL(new URLRequest(returnURL(event.target.name)));
}
}
function returnURL(t:String):String {
return resetString(resultXML.area.(@id==t).@url);
}
appBg.appTitle.text = loaderInfo.parameters.t;
function mapMove(event:MouseEvent): void {
//mapBord.x=32-(mouseX-stage.stageWidth/2)/12;
//mapBord.y=30-(mouseY-stage.stageHeight/2)/12;
}
// 鼠标移动到某个省市上的事件
function mapHit(event:MouseEvent): void {
//得到输入的xml中的value值
var s :String = returnValue(event.target.name);
//鼠标放到具体省市上的相应图变色
event.target.nextFrame();
//有值
if(s.length > 2)
{
//显示
showTip(event.target.name);
}
else
{
//隐藏上次显示的tip
tipBord.visible=false;
}
}
function mapOut(event:MouseEvent): void {
event.target.prevFrame();
//hideTip();
}
function showTip(t:String): void {
tipBord.visible=true;
tipBord.t.htmlText=returnValue(t);
var tz:Object={x:0,y:0};
tz.x=mapBord.textBord.getChildByName(t).x;
tz.y=mapBord.textBord.getChildByName(t).y;
var p:Number=0;
var l:Number=0;
if(tz.x>stage.stageWidth/2) {
p=-120;
} else {
p=120;
}
if(tz.y>stage.stageHeight/2) {
l=-120;
} else {
l=120;
}
tipBord.x=tz.x+p;
tipBord.y=tz.y+l;
gs.graphics.clear();
gs.graphics.lineStyle(1, 0xFFFFFF,0.1);
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.2);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.1);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.2);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.1);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
}
function hideTip(): void {
tipBord.visible=false;
tipBord.t.htmlText="";
gs.graphics.clear();
}
function visibleTip(event:MouseEvent): void {
tipBord.visible=true;
}
function returnValue(t:String):String {
return resetString(resultXML.area.(@id==t).@value);
}
function resetString(s:String):String {
var a:Array=s.split(",");
var t:String="";
for(var i:uint=0;i<a.length;i++) {
t+=a[i]+"\n";
}
return t;
}
stop();
tipBord.visible = false ;
mapBord.addEventListener(MouseEvent.MOUSE_MOVE,mapMove);
mapBord.map.addEventListener(MouseEvent.MOUSE_OVER,mapHit);
mapBord.map.addEventListener(MouseEvent.MOUSE_OUT,mapOut);
mapBord.textBord.addEventListener(MouseEvent.MOUSE_OVER,visibleTip);
mapBord.map.addEventListener(MouseEvent.CLICK,openURL);
tipBord.addEventListener(MouseEvent.MOUSE_OVER,visibleTip);
// 鼠标点击事件
function openURL(event:MouseEvent): void {
var url:String = returnURL(event.target.name);
if(url.length > 4)
{
navigateToURL(new URLRequest(returnURL(event.target.name)));
}
}
function returnURL(t:String):String {
return resetString(resultXML.area.(@id==t).@url);
}
appBg.appTitle.text = loaderInfo.parameters.t;
function mapMove(event:MouseEvent): void {
//mapBord.x=32-(mouseX-stage.stageWidth/2)/12;
//mapBord.y=30-(mouseY-stage.stageHeight/2)/12;
}
// 鼠标移动到某个省市上的事件
function mapHit(event:MouseEvent): void {
//得到输入的xml中的value值
var s :String = returnValue(event.target.name);
//鼠标放到具体省市上的相应图变色
event.target.nextFrame();
//有值
if(s.length > 2)
{
//显示
showTip(event.target.name);
}
else
{
//隐藏上次显示的tip
tipBord.visible=false;
}
}
function mapOut(event:MouseEvent): void {
event.target.prevFrame();
//hideTip();
}
function showTip(t:String): void {
tipBord.visible=true;
tipBord.t.htmlText=returnValue(t);
var tz:Object={x:0,y:0};
tz.x=mapBord.textBord.getChildByName(t).x;
tz.y=mapBord.textBord.getChildByName(t).y;
var p:Number=0;
var l:Number=0;
if(tz.x>stage.stageWidth/2) {
p=-120;
} else {
p=120;
}
if(tz.y>stage.stageHeight/2) {
l=-120;
} else {
l=120;
}
tipBord.x=tz.x+p;
tipBord.y=tz.y+l;
gs.graphics.clear();
gs.graphics.lineStyle(1, 0xFFFFFF,0.1);
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.2);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.1);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.2);
gs.graphics.lineTo(tipBord.x-32+tipBord.width-8,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
gs.graphics.moveTo(tz.x+12,tz.y+6);
gs.graphics.beginFill(0x0077CC,0.1);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30+tipBord.height-8);
gs.graphics.lineTo(tipBord.x-32,tipBord.y-30);
gs.graphics.lineTo(tz.x+12,tz.y+6);
gs.graphics.endFill();
}
function hideTip(): void {
tipBord.visible=false;
tipBord.t.htmlText="";
gs.graphics.clear();
}
function visibleTip(event:MouseEvent): void {
tipBord.visible=true;
}
function returnValue(t:String):String {
return resetString(resultXML.area.(@id==t).@value);
}
function resetString(s:String):String {
var a:Array=s.split(",");
var t:String="";
for(var i:uint=0;i<a.length;i++) {
t+=a[i]+"\n";
}
return t;
}
demo and source
demo and source other address for download