ChinaMap

package {
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.external.ExternalInterface;
import flash.geom.ColorTransform;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.StaticText;
import flash.text.TextField;
import flash.text.TextFormat;

[SWF(width="600",height="500",frameRate="25",backgroundColor="#FFFFFF")]

public class ChinaMap extends Sprite {

private var mapConfig:Object;
private var mapBackGroud:MapBackgound;
private var mapArea:MapArea;
private var mapXML:XMLList;
private var mapTip:MapTip;
private var tipShandow:Sprite;
private var wrapperFunction:String;

public function ChinaMap(){
mapConfig = new Object();
mapConfig.title = loaderInfo.parameters.title;
wrapperFunction = loaderInfo.parameters.jsHandler;
/*UI*/
var mapLoading:MapLoading = new MapLoading();
addChild(mapLoading);
var xmlLoader:URLLoader = new URLLoader();
var xmlAdress:String = (loaderInfo.parameters.xmlurl != null)?loaderInfo.parameters.xmlurl:"data/d.xml";
xmlLoader.addEventListener(Event.COMPLETE,function(e:Event):void{
mapXML = new XML(e.target.data).area;
removeChild(mapLoading);
drawUI();
});
xmlLoader.load(new URLRequest(xmlAdress));
}

private function drawUI():void {
mapBackGroud = new MapBackgound();
mapBackGroud.title = (mapConfig.title == null)?"you need set title":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;
}

private function registAction(c:DisplayObjectContainer):void {
var me:DisplayObject;
var meTf:DisplayObject;
var meTf1: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).value = node.@value;
(me as MovieClip).navUrl = node.@url;
(me as MovieClip).navTarget = node.@target;
(me as MovieClip).buttonMode = true;
var color:ColorTransform = new ColorTransform;
// var color24:Number=0x00 << 16 | Math.random()*0xff << 8 | 0x00;
// color.color=color24;
chanceColor(color);
(me as MovieClip).transform.colorTransform=color;
(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;
}
}

for(var k:uint = 0; k<(me as MovieClip).numChildren;k++){
meTf = (me as MovieClip).getChildAt(k);
if(meTf is MovieClip){
meTf1 = (meTf as MovieClip).getChildAt(0);
if(meTf1 is StaticText){
(meTf as MovieClip).removeChildAt(0);
}else{
if(meTf1 is MovieClip){
if(me.name=="gansu"){
for(var j:uint = 0; j<(meTf1 as MovieClip).numChildren;j++){
var meTf3:DisplayObject = (meTf1 as MovieClip).getChildAt(j);
if(meTf3 is StaticText){
(meTf1 as MovieClip).removeChild(meTf3);
}
}
}else{
var meTf2 :DisplayObject = (meTf1 as MovieClip).getChildAt(0);
if(meTf2 is StaticText){
(meTf1 as MovieClip).removeChildAt(0);
}
}
}
}
}
}
}
}
function chanceColor(c:ColorTransform):void{
var color24:Number=0x00 << 16 | Math.random()*0xff << 8 | 0x00;
c.color=color24;
}
function chanceColor11(c:ColorTransform):void{
var n:Number=Math.random();
if(n<.3) c.redOffset=255;
else if(n<.6) c.greenOffset=255;
else{
c.redOffset=255;
c.greenOffset=255;
}
}
function mapOverHandler(e:MouseEvent):void {
(e.currentTarget as MovieClip).gotoAndStop(2);
showTip((e.currentTarget as MovieClip),(e.currentTarget as MovieClip).value);
}
function mapOutHandler(e:MouseEvent):void {
(e.currentTarget as MovieClip).gotoAndStop(1);
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;
if(me.navUrl != null) {
navigateToURL(new URLRequest(me.navUrl),me.navTarget);
}
var clickEvent:MapEvent = new MapEvent(MapEvent.ITEMCLICK,true,true);
clickEvent.value = me.name;
dispatchEvent(clickEvent);
if (ExternalInterface.available) {
try {
var t:Object = new Object();
t.value = me.name;
ExternalInterface.call(wrapperFunction,t);
} catch(err:Error) {
trace(err);
}
}
}
}

private function showTip(mc:MovieClip,t:String):void {
mapTip.addEventListener(Event.ENTER_FRAME,moveTip);
mapTip.visible = true;
mapTip.t.htmlText = t;
}
private function hideTip():void {
mapTip.visible=false;
mapTip.t.text="";
mapTip.removeEventListener(Event.ENTER_FRAME,moveTip);
}

private 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;
}
}

private 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();
}
}
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值