My favorites
▼
|
Sign in
chinamapforflash
An Flash Component for China Area Map
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
src
/
ChinaMap.as
r3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.external.ExternalInterface;
[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;
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;
(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).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();
}
}
}
}
}
Show details
Hide details
Change log
r2
by guoshaorui on Aug 8, 2009
Diff
[No log message]
Go to:
/trunk/.actionScriptProperties
/trunk/.project
/trunk/.settings
...org.eclipse.core.resources.prefs
/trunk/assets
/trunk/assets/map.fla
/trunk/assets/map.swf
/trunk/bin-debug
/trunk/bin-debug/AC_OETags.js
/trunk/bin-debug/ChinaMap.html
/trunk/bin-debug/ChinaMap.swf
/trunk/bin-debug/ChinaMapDemo.html
/trunk/bin-debug/ChinaMapDemo.swf
/trunk/bin-debug/data
/trunk/bin-debug/data/d.xml
/trunk/bin-debug/demo.html
/trunk/bin-debug/history
...nk/bin-debug/history/history.css
/trunk/bin-debug/history/history.js
...-debug/history/historyFrame.html
...n-debug/playerProductInstall.swf
/trunk/bin-debug/swfobject.js
/trunk/bin-release
/trunk/bin-release/AC_OETags.js
/trunk/bin-release/ChinaMap.html
/trunk/bin-release/ChinaMap.swf
/trunk/bin-release/history
.../bin-release/history/history.css
...k/bin-release/history/history.js
...elease/history/historyFrame.html
...release/playerProductInstall.swf
/trunk/html-template
/trunk/html-template/AC_OETags.js
/trunk/html-template/history
...tml-template/history/history.css
...html-template/history/history.js
...mplate/history/historyFrame.html
...tml-template/index.template.html
...emplate/playerProductInstall.swf
/trunk/lib
/trunk/lib/map.swc
/trunk/lib/map.swf
/trunk/src
/trunk/src/ChinaMap.as
/trunk/src/ChinaMapDemo.as
/trunk/src/data
/trunk/src/data/d.xml
/trunk/src/event
/trunk/src/event/MapEvent.as
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 4587 bytes, 141 lines
View raw file
Powered by
Google Project Hosting