-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathWebView.as
More file actions
150 lines (142 loc) · 3.39 KB
/
WebView.as
File metadata and controls
150 lines (142 loc) · 3.39 KB
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
142
143
144
145
146
147
148
149
150
package
{
import appManager.event.PageControllEvent;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.media.StageWebView;
public class WebView extends MovieClip
{
public static const LOAD_URL:String = "LOAD_URL";
public static const LOAD_STRING:String = "LOAD_STRING";
public static const LOAD_BITMAP:String = "LOAD_BITMAP";
private static var Me:WebView;
public static var autoShowHide:Boolean=true;
private var _stageWebView:StageWebView;
private var _area:MovieClip;
private var _url:String;
private var _stage:Stage;
private var _loadStatus:String;
private var _bitmapData:BitmapData;
private var _preventerDisplayObject:DisplayObject;
public function WebView()
{
super();
}
public static function setup(area_p:MovieClip,url_p:String,stage_p:Stage,loadStatus_p:String=LOAD_URL,bitmapData_p:BitmapData=null,PreventerDisplayObject:DisplayObject=null):void
{
Me = new WebView();
Me._area = area_p;
Me._url = url_p;
Me._stage = stage_p;
Me._loadStatus = loadStatus_p;
Me._bitmapData = bitmapData_p;
Me._preventerDisplayObject = PreventerDisplayObject;
if(PreventerDisplayObject!=null)
{
PreventerDisplayObject.dispatchEvent(new PageControllEvent(PageControllEvent.PREVENT_PAGE_CHANGING,letPageChange,PreventerDisplayObject));
}
Me.load();
}
protected static function letPageChange():void
{
if(isActive())
{
unload();
}
else
{
Me._preventerDisplayObject.dispatchEvent(new PageControllEvent(PageControllEvent.LET_PAGE_CHANGE));
}
}
private function chekArea(event:Event):void
{
// TODO Auto-generated method stub
_stageWebView.viewPort = getArea();
if(!Obj.isAccesibleByMouse(_area))
{
_hide();
}
else
{
_show();
}
}
private function load():void
{
_stageWebView = new StageWebView(true);
_stageWebView.stage = _stage;
_stageWebView.viewPort = getArea();
if(_loadStatus==LOAD_URL)
{
_stageWebView.loadURL(_url);
}
else if(_loadStatus==LOAD_STRING)
{
_stageWebView.loadString(_url);
}
else if(_loadStatus == LOAD_BITMAP)
{
_stageWebView.drawViewPortToBitmapData(_bitmapData);
}
Me.addEventListener(Event.ENTER_FRAME,chekArea)
}
public static function reLoad(url_p:String):void
{
Me._url = url_p;
Me.reLoad();
}
private function reLoad():void
{
if(_loadStatus==LOAD_URL)
{
_stageWebView.loadURL(_url);
}
else
{
_stageWebView.loadString(_url);
}
}
public static function unload():void
{
if(Me!=null)Me.remove();
}
private function remove():void
{
if(isActive())
{
Me.removeEventListener(Event.ENTER_FRAME,chekArea)
_stageWebView.stage = null;
_stageWebView.dispose();
_stageWebView = null
}
}
private function getArea():Rectangle
{
return _area.getBounds(_stage)
}
public static function hide():void
{
if(Me!=null)Me._hide();
}
public static function show():void
{
if(Me!=null)Me._show();
}
private function _hide():void
{
if(isActive() && autoShowHide)_stageWebView.stage = null;
}
private function _show():void
{
if(isActive()&& autoShowHide)_stageWebView.stage = _stage;
}
public static function isActive():Boolean
{
return Me._stageWebView!=null
}
}
}