http://www.cnblogs.com/crkay/archive/2010/05/31/1747947.html
原理的话就是使用[frame()]标签,改变文档类指向。具体操作大家可以去网路上查一下,这方面资料很多,我这里只将源码贴出来,和大家一同分享。 |
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
1
默认程序入口:
2
3
package
4
{
5
import
flash.display.Sprite;
6
import
mx.core.BitmapAsset;
7
8
[Frame(factoryClass
=
"
SystemManager
"
,label
=
"
hello
"
)]
9
10
public
class
MyApplication
extends
Sprite {
11
12
[Embed(source
=
"
test.png
"
)]
13
private
var bigPicCls:Class;
14
15
public
function MyApplication() {
16
var b:BitmapAsset
=
new
bigPicCls() as BitmapAsset;
17
addChild(b);
18
}
19
}
20
}
21
22
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
1
被指向的主文档类:
2
3
package
{
4
import
flash.display.DisplayObject;
5
import
flash.display.MovieClip;
6
import
flash.display.StageAlign;
7
import
flash.display.StageScaleMode;
8
import
flash.events.Event;
9
import
flash.events.ProgressEvent;
10
import
flash.utils.getDefinitionByName;
11
12
public
class
SystemManager
extends
MovieClip
13
{
14
private
var preLoader:PreLoader;
15
16
public
function SystemManager() {
17
stage.scaleMode
=
StageScaleMode.NO_SCALE;
18
stage.align
=
StageAlign.TOP_LEFT;
19
20
stop();
21
22
preLoader
=
new
PreLoader();
23
addChild(preLoader);
24
25
preLoader.x
=
stage.stageWidth
/
2
-
preLoader.width
/
2
;
26
preLoader.x
=
stage.stageHeight
/
2
-
preLoader.height
/
2
;
27
28
loaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandle);
29
loaderInfo.addEventListener(Event.COMPLETE,completeHandler);
30
}
31
32
private
function progressHandle(e:ProgressEvent):
void
33
{
34
preLoader.setProgress(e.bytesLoaded,e.bytesTotal);
35
}
36
37
private
function completeHandler(e:Event):
void
{
38
loaderInfo.removeEventListener(ProgressEvent.PROGRESS,progressHandle);
39
loaderInfo.removeEventListener(Event.COMPLETE,completeHandler);
40
41
removeChild(preLoader);
42
preLoader
=
null
;
43
44
nextFrame();
45
46
initApplication();
47
}
48
49
private
function initApplication():
void
{
50
/**
这里不能直接写成:
51
var app:Application = new Application();
52
这样的由于引用到 Application,Application中所有的资源都会被编译到第一帧来
53
这样的话 PreLoader就没有意义了,你也看不到PreLoader,就跳到第二帧了
54
*
*/
55
var appCls:Class
=
getDefinitionByName(
"
MyApplication
"
) as Class;
56
var app:DisplayObject
=
new
appCls() as DisplayObject;
57
addChild(app);
58
}
59
}
60
}
61
62
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
1
进度条:
2
3
package
4
{
5
import
flash.display.Sprite;
6
import
flash.text.TextField;
7
8
public
class
PreLoader
extends
Sprite
9
{
10
public
function PreLoader()
11
{
12
var t:TextField
=
new
TextField();
13
t.border
=
true
;
14
t.text
=
"
loading......
"
;
15
16
addChild(t);
17
}
18
19
public
function setProgress(loaded:uint,total:uint):
void
20
{
21
var t:TextField
=
getChildAt(
0
) as TextField;
22
t.text
=
"
load:
"
+
loaded
/
1000
+
"
/
"
+
total
/
1000
;
23
24
trace(
"
load:
"
+
loaded
/
1000
+
"
/
"
+
total
/
1000
);
25
}
26
}
27
}
28