Loading制作资料
, s0 ~5 U) {5 O+ ILoading的制作都是使用这些AS,那些样子不同的Loading只是表现手法不一样,AS都是大同小异的,自己看看就明白了
& e2 H2 d6 F3 l, ]) U! u
' c9 o( h4 y' p8 _; u+ l1 Apackage {, A2 O {( F/ y
import flash.display.Loader;
1 x, k4 b+ w* G. |3 F9 kimport flash.display.Sprite;
5 f+ X' T) K! M. f) n( Q3 n* Wimport flash.events.*;
) b+ [; P' e2 G, W' G8 Cimport flash.net.URLRequest;
% q' a* S+ {; D1 [2 N2 vimport flash.text.*;1 D! E4 n U+ v d: J
import flash.display.LoaderInfo;
( W9 {3 s2 d ?9 oimport flash.display.Graphics;0 F% Z8 [+ ~* p5 ^, t
public class Exam extends Sprite {
1 G" K; e1 b8 p& i0 @ private var [url=String]url:String[/url] = "aa.jpg";1 [ n( x) Z% C y
private var __txt:TextField;* ^1 \ i. B4 o, h; n1 G" p
public function Exam() {6 i6 Q* O( |! `: X
__txt=new TextField();
- s) s7 [" E" E0 t# v E addChild(__txt);
5 s @+ _+ s+ Y7 ^, Z __txt.type=TextFieldType.DYNAMIC;//创建文本的类型
& g# `. ]1 o: E, N, B* q# \ __txt.width=255;
7 K+ o$ L( {0 h0 W, x* P6 L' I __txt.height=50;
( l5 f# v7 |6 f- { __txt.name="mytxt";
6 o0 D. w: ~2 _) M. w5 v: J __txt.multiline=false;( h! N8 V$ z; {4 b" |. a {
__txt.x=10;- r( s7 h( g* w; |' E2 f$ A
__txt.y=250;
9 R: r5 i/ Y6 H: g1 \* W __txt.background=true;
3 h, C! m3 P: u; h __txt.backgroundColor=0xeeeeee;
/ X2 Z2 J3 F0 M- W5 g; q& f __txt.border=true;' u$ i3 Y* {4 y
__txt.borderColor=0x999999;
" @0 `0 A4 t- p$ h; \2 Y" p __txt.wordWrap=true;//自动换行( Q- W& B& T$ @0 b* a
var loader: Loader = new Loader();! n+ {" P( o% W+ p5 a
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);2 F& K; K# Q) J$ L8 t
var request:URLRequest = new URLRequest(url);0 _& V' I1 U3 J( f% I4 T
loader.load(request);
, h& U4 M/ g! W" b: D& m7 m addChild(loader);
0 U5 H$ q/ k5 Y$ E% r9 |2 b# b }1 P; ?0 D9 @; L* b
private function progressHandler(event: ProgressEvent):void {
! {5 o7 J5 H. X& x var percent:Number=event.bytesLoaded/event.bytesTotal;* X( n/ `5 R* D+ i: R8 o
percent=int(percent*100)/100;6 C9 x# j# C. \* p8 @
__txt.text="完成"+percent*100+"%"+" 已下载:"+event.bytesLoaded+"/总字节数:"+event.bytesTotal;
2 ?4 w9 W/ o. T" t- z graphics.clear();: x. P$ M- O- E# u
graphics.beginFill(0x666666);
: x7 e$ E) i" { graphics.drawRect(10,220,percent*200,10);
" a! t1 _7 j& n7 l$ N9 I5 _* x+ l graphics.endFill();) o0 X3 Q# i" }
}' |* H( ?% V1 ^; c4 x! l3 z7 C% v7 Q
}: N/ I I# Y/ j7 U7 b7 m2 l7 }
} d1 P3 m% `7 t4 g4 ~2 V
如果我们想知道当前的加载进度,并想把它像AS1,AS2一样写在帧上.我们可以像以下这样写; I! O* i1 k3 d$ K
stop();
/ d; N/ P7 `/ f' Lvar txt=new TextField();
9 P6 V. ^, G: R' [% stxt.text="AS3 Loading...";
% ~% N3 ~( @# W0 mtxt.textColor=0x000000;8 s5 M# G& @6 K, W2 x0 T0 e9 g
txt.selectable=false;- m% G9 n; u6 c: j$ y# [1 H3 ]
txt.x=10;
$ f7 s( w V. J8 [, M0 N& ~$ Atxt.y=10;% u: ?1 {4 F \9 p
addChild(txt).name="txt";
# ?% i+ L* ^$ a4 P' J6 j' ~var loadbar=new Sprite();0 q7 w$ Q' ~& h
loadbar.graphics.lineStyle(1,0x000000,1);
# ]$ O( A& c3 F: H7 j- Bloadbar.graphics.beginFill(0x666666,.5);( s8 d, G2 o3 o' ~+ J
loadbar.graphics.drawRect(0,0,200,10);
* h! T: f0 i0 {% ~( nloadbar.graphics.endFill();
+ ~1 j/ l3 {2 I D& ~" l" G: @0 |& Lloadbar.x=10;
8 t5 Q/ {' ^; b2 a% l$ S; Vloadbar.y=30;
) X1 y* b3 K0 k4 faddChild(loadbar);
; R. K. u% Z1 w+ E6 Z) C5 ^6 |1 H1 M0 r
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,loading);& N7 A7 _& y+ S3 F! U0 }- ]
this.loaderInfo.addEventListener(Event.COMPLETE,loaded);" v- d/ l- K- o; i
function loading(eve) {" c5 L/ c/ V, x+ g
var loadpre:int=eve.bytesLoaded/eve.bytesTotal*100;
2 o% H b, Z' w6 P: F txt.text="影片载入"+loadpre+" %";
3 x& Y$ B- u& W" l4 x5 `" B n loadbar.scaleX=loadpre/100;
5 G8 v: p& ^2 I: v}' J4 G% w1 @3 m
//显示进度载入百分比-----, E: l9 G) ?3 r$ ?
function loaded(eve) {
* r1 A1 N; @" z- r" \ txt.text="影片载入完毕!";
6 H" B' z3 d, G( a) \1 S}. z/ c9 u2 F# S: u" P6 ?( F
; O3 Q, [; Y0 H# l[ 本帖最后由 C.Xiao 于 2008-7-4 22:59 编辑 ]