相对原创,
1 增加color,可以设定初始时每块地方的色,然后移动此标时,相应的做改变
2 增加点击后弹出对话框,同意后,才进入下个页面,不同意或是没有定义下个页面时不反应
3 同时给js传出更多的内容,基本上把xml设定都传出了,给修改更加方便.
4 因为用到as3所以,我没有用array这些,因为有点麻烦.直接就一字符串,再用js的split断开来分开去取对应的值
//ChinaMap.as
//在fla中的第一贞用include "ChinaMap.as"引入就可以直接编辑fla了
//这个文件放在fla一个文件夹
import event.MapEvent;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.external.ExternalInterface;
var debug = 1;//取消调试0
//System.useCodePage = true; //AS3。0的话
var mapConfig:Object;
var mapBackGroud:MapBackgound;
var mapArea:MapArea;
var mapXML:XMLList;
var mapTip:MapTip;
var tipShandow:Sprite;
var wrapperFunction:String;
function ChinaMap(){
mapConfig = new Object();
mapConfig.title = loaderInfo.parameters.title;
wrapperFunction = loaderInfo.parameters.jsHandler;
wrapperFunction = (wrapperFunction==null)?"swf_js":wrapperFunction;
/*UI*/
var mapLoading:MapLoading = new MapLoading();
addChild(mapLoading);
var xmlLoader:URLLoader = new URLLoader();
var xmlAdress:String = (loaderInfo.parameters.xmlurl != null)?loaderInfo.parameters.xmlurl:"data.xml";
xmlLoader.addEventListener(Event.COMPLETE,function(e:Event):void{
mapXML = new XML(e.target.data).area;
removeChild(mapLoading);
drawUI();
});
xmlLoader.load(new URLRequest(xmlAdress));
}
function drawUI():void {
mapBackGroud = new MapBackgound();
mapBackGroud.title = (mapConfig.title == null)?"CHINA MAP":mapConfig.title;
addChild(mapBackGroud);
mapArea = new MapArea();
mapArea.x = mapArea.y = 20;
addChild(mapArea);
stopAll(mapArea.map);
registAction(mapArea.map);
tipShandow = new Sprite();
addChild(tipShandow);
mapTip = new MapTip();
addChild(mapTip);
mapTip.visible = false;
}
function registAction(c:DisplayObjectContainer):void {
var me:DisplayObject;
for(var i:uint = 0; i<c.numChildren; i++) {
me = c.getChildAt(i);
if(me is MovieClip && me.name != "bg") {
me.alpha = 0.5;
f:for each(var node:XML in mapXML){
if(node.@id == me.name) {
me.alpha = 1;
(me as MovieClip).title = node.@title;
(me as MovieClip).color_n = node.@color == 1 ? 1 : 2;
(me as MovieClip).gotoAndStop((me as MovieClip).color_n);
(me as MovieClip).value = node.@value;
(me as MovieClip).navUrl = node.@url;
(me as MovieClip).navTarget = node.@target;
(me as MovieClip).buttonMode = true;
(me as MovieClip).addEventListener(MouseEvent.MOUSE_OVER,mapOverHandler);
(me as MovieClip).addEventListener(MouseEvent.MOUSE_OUT,mapOutHandler);
(me as MovieClip).addEventListener(MouseEvent.CLICK,mapClipHandler);
break f;
}
}
}
}
function mapOverHandler(e:MouseEvent):void {
(e.currentTarget as MovieClip).color_n == 1 ? (e.currentTarget as MovieClip).gotoAndStop(2) : (e.currentTarget as MovieClip).gotoAndStop(1) ;
showTip((e.currentTarget as MovieClip),(e.currentTarget as MovieClip).value);
}
function mapOutHandler(e:MouseEvent):void {
(e.currentTarget as MovieClip).color_n == 1 ? (e.currentTarget as MovieClip).gotoAndStop(1) : (e.currentTarget as MovieClip).gotoAndStop(2) ;
if(mouseX < mapTip.x || mouseX > (mapTip.x+mapTip.width) || mouseY < mapTip.y || mouseY > (mapTip.y+mapTip.height)) {
hideTip();
}
}
function mapClipHandler(e:MouseEvent):void {
var me:MovieClip = e.currentTarget as MovieClip;
var clickEvent:MapEvent = new MapEvent(MapEvent.ITEMCLICK,true,true);
clickEvent.value = me.name;
dispatchEvent(clickEvent);
var can_open = 0;
if (ExternalInterface.available) {
try {
can_open = ExternalInterface.call(wrapperFunction,
me.name
+ "," + me.title
+ "," + me.value
+ "," + me.color_n
+ "," + me.navUrl
+ "," + me.navTarget
+ "," + me.buttonMode
);
} catch(err:Error) {
trace(err);
}
}
if(can_open && (me.navUrl != null) ) {
navigateToURL(new URLRequest(me.navUrl),me.navTarget);
}
}
}
function showTip(mc:MovieClip,t:String):void {
mapTip.addEventListener(Event.ENTER_FRAME,moveTip);
mapTip.visible = true;
mapTip.t.htmlText = t;
}
function hideTip():void {
mapTip.visible=false;
mapTip.t.text="";
mapTip.removeEventListener(Event.ENTER_FRAME,moveTip);
}
function moveTip(e:Event):void {
e.currentTarget.x = mouseX+10;
e.currentTarget.y = mouseY+10;
if((e.currentTarget.x+e.currentTarget.width) > stage.stageWidth) {
e.currentTarget.x = stage.stageWidth - e.currentTarget.width;
}
}
function stopAll(c:DisplayObjectContainer):void {
var me:DisplayObject;
for(var i:uint = 0; i<c.numChildren; i++) {
me = c.getChildAt(i);
if(me is MovieClip) {
(me as MovieClip).stop();
}
}
}
function web_tip(text)
{
if (debug)
navigateToURL(new URLRequest("test_" + text),"_blank");
}
ChinaMap();
stop();
map.fla到网上查找即可
<!--data.xml,放fla同一目录//-->
<?xml version="1.0" encoding="utf-8"?>
<data>
<area id="beijing" title="北京" value="北京,人口:100万,面积:380万平方公里,主要交通工具:自行车" url="test.htm" color="1" target="_blank"/>
<area id="tianjin" title="天津" value="天津" url="test1.htm" color="1" target="_self"/>
<area id="xinjiang" title="新疆" value="<font color="#990000" size="18">这是HTML字体</font>"/>
<area id="xizang" title="西藏" value="西藏" url="test3.htm" color="2" target="_blank"/>
<area id="qinghai" title="青海" value="青海" url="test.htm" color="2" target="_blank"/>
<area id="gansu" title="甘肃" value="甘肃" url="test.htm" color="2" target="_blank"/>
<area id="neimenggu" title="内蒙古" value="内蒙古" url="test.htm" color="1" target="_blank"/>
<area id="ningxia" title="宁夏" value="宁夏" url="test.htm" color="2" target="_blank"/>
<area id="shanxi" title="山西" value="山西" url="test.htm" color="2" target="_blank"/>
<area id="liaoning" title="辽宁" value="辽宁" url="test.htm" color="2" target="_blank"/>
<area id="jilin" title="吉林" value="吉林" url="test.htm" color="1" target="_blank"/>
<area id="heilongjiang" title="黑龙江" value="黑龙江" url="test.htm" color="1" target="_blank"/>
<area id="hebei" title="河北" value="河北" url="test.htm" color="1" target="_blank"/>
<area id="shandong" title="山东" value="山东" url="test.htm" color="1" target="_blank"/>
<area id="henan" title="河南" value="河南" url="test.htm" color="1" target="_blank"/>
<area id="shannxi" title="陕西" value="陕西" url="test.htm" color="1" target="_blank"/>
<area id="sichuan" title="四川" value="四川" url="test.htm" color="1" target="_blank"/>
<area id="chongqing" title="重庆" value="重庆" url="test.htm" color="1" target="_blank"/>
<area id="hubei" title="湖北" value="湖北" url="test.htm" color="1" target="_blank"/>
<area id="anhui" title="安徽" value="安徽" url="test.htm" color="1" target="_blank"/>
<area id="jiangsu" title="江苏" value="江苏" url="test.htm" color="1" target="_blank"/>
<area id="shanghai" title="上海" value="上海" url="test.htm" color="1" target="_blank"/>
<area id="zhejiang" title="浙江" value="浙江" url="test.htm" color="1" target="_blank"/>
<area id="fujian" title="福建" value="福建" url="test.htm" color="1" target="_blank"/>
<area id="taiwan" title="台湾" value="台湾" url="test.htm" color="1" target="_blank"/>
<area id="jiangxi" title="江西" value="江西" url="test.htm" color="1" target="_blank"/>
<area id="hunan" title="湖南" value="湖南" url="test.htm" color="1" target="_blank"/>
<area id="guizhou" title="贵州" value="贵州" url="test.htm" color="1" target="_blank"/>
<area id="guangxi" title="广西" value="广西" url="test.htm" color="1" target="_blank"/>
<area id="guangdong" title="广东" value="广东" url="test.htm" color="1" target="_blank"/>
<area id="xianggang" title="香港" value="香港" url="test.htm" color="2" target="_blank"/>
<area id="hainan" title="海南" value="海南" url="test.htm" color="2" target="_blank"/>
<area id="yunnan" title="云南" value="云南" url="test.htm" color="1" target="_blank"/>
</data>
<!--index.html 显示swf文件//-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;" lang="ch">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
<mce:script type="text/javascript" src="swfobject.js" mce_src="swfobject.js"></mce:script>
<mce:script type="text/javascript"><!--
function swf_js(e) {
/*
me.name 0名字
+ "," + me.title 1标题
+ "," + me.value 2也是
+ "," + me.color_n 3初始色
+ "," + me.navUrl 4地址
+ "," + me.navTarget 5 打开窗口
+ "," + me.buttonMode 6按钮方式
*/
var splits = e.split(",");
if ( (splits[4] != "") && confirm("你要查看[" + splits[1] + "]的详细分布情况吗?"))//修改时,可以修改双引号中的内容,但""号内不能再出现",
//可以使用splits[x]取到xml中定制的内容.x是上面的说明
return 1;
return 0;
}
// --></mce:script>
</head>
<body id="player">
<!--容器end-->
<div id="container">Get the Flash Player to see this player</div>
<!--容器end-->
<!--init code-->
<mce:script type="text/javascript"><!--
var s1 = new SWFObject("map.swf","ply","600","500","10","#FFFFFF");//载入swf,名字是map,swf
s1.addParam("allowfullscreen","true"); //允许全屏
s1.addParam("allownetworking","all");
s1.addParam("allowscriptaccess","none");
s1.addParam("wmode","transparent");
s1.addVariable("jsHandler","swf_js");//调用的js不能动.
s1.addVariable("title","中国地图"); //出现在地图左上角的地图的名字,可以改 中国地图 成自己要的.
s1.addVariable("xmlurl","data.xml"); //xml的路径.这个没必要改.
s1.write("container");
// --></mce:script>
<!--/init code-->
</body>
</html>
playerProductInstall.swf文件网上下载是在flash play控件不全用时下载.
在共享包中有.
//swfobject.js载入swf js
/**
* SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
*
* SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*/
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=/"application/x-shockwave-flash/" src="/" mce_src="/"""+this.getAttribute("swf")+"/" width=/""+this.getAttribute("width")+"/" height=/""+this.getAttribute("height")+"/" style="/" mce_style="/"""+this.getAttribute("style")+"/"";_19+=" id=/""+this.getAttribute("id")+"/" name=/""+this.getAttribute("id")+"/" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=/""+_1a[key]+"/" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=/""+_1c+"/"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=/""+this.getAttribute("id")+"/" classid=/"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000/" width=/""+this.getAttribute("width")+"/" height=/""+this.getAttribute("height")+"/" style="/" mce_style="/"""+this.getAttribute("style")+"/">";_19+="<param name=/"movie/" value=/""+this.getAttribute("swf")+"/" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=/""+key+"/" value=/""+_1d[key]+"/" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=/"flashvars/" value=/""+_1f+"/" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|/s)+/,"").replace(/(/s+r|/s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
//在fla目录下创建一目录event
//放此as:MapEvent.as
package event
{
import flash.events.Event;
public class MapEvent extends Event
{
public static var ITEMCLICK:String = "itemClick";
public var value:String;
public function MapEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
}
从网上下载map.fla下来和保存好这些文件后,打开flash 10就写入include as就可以导出swf使用了.