//이미지 불러오기
var url:String = "loaderTest.png";
var URLreq:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.load(URLreq);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
loadComplete);
function loadComplete(e:Event){
var img:Sprite = new Sprite();
img.addChild(e.target.content);
addChild(img);
img.buttonMode = true;
img.x = 50;
img.addEventListener(MouseEvent.MOUSE_DOWN,
imgOnMouse);
img.addEventListener(MouseEvent.MOUSE_UP,
imgOffMouse);
trace("Image Loading Complete");
}
function imgOnMouse(e:MouseEvent){e.target.startDrag();}
function imgOffMouse(e:MouseEvent){this.stopDrag();}
//SWF 불러오기
var swfUrl:String = "LoaderTest.swf";
var swfURLreq:URLRequest = new URLRequest(swfUrl);
var swfLoader:Loader = new Loader();
swfLoader.load(swfURLreq);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
swfLoadComplete);
function swfLoadComplete(e:Event){
addChild(swfLoader);
trace("SWF Loading Complete");
}
//Sound 불러오기 -일반 Loader가 아닌 Sound를 사용.
var sndUrl:String = "loaderTest.mp3";
var sndURLreq:URLRequest = new URLRequest(sndUrl);
var snd:Sound = new Sound();
var channel:SoundChannel = new SoundChannel(); //사운드 일시정지
기록용
snd.load(sndURLreq);
snd.addEventListener(ProgressEvent.PROGRESS, sndLoadProgress);
snd.addEventListener(Event.COMPLETE, sndLoadComplete);
function sndLoadProgress(e:ProgressEvent){
var loadPercent = Math.round(100*(e.bytesLoaded/e.bytesTotal));
trace("Sound is", loadPercent,
"% Loaded...");
}
function sndLoadComplete(e:Event){
channel=snd.play(channel.position);
trace("Sound Loading Complete");
musicCont.playBtn.addEventListener(MouseEvent.MOUSE_DOWN,musicStart);
musicCont.pauseBtn.addEventListener(MouseEvent.MOUSE_DOWN,musicPause);
musicCont.stopBtn.addEventListener(MouseEvent.MOUSE_DOWN,musicStop);
channel.addEventListener(Event.SOUND_COMPLETE,
musicEnd);
}
function musicStart(e:MouseEvent){
channel=snd.play(channel.position);
channel.addEventListener(Event.SOUND_COMPLETE,
musicEnd);
}
function musicPause(e:MouseEvent){SoundMixer.stopAll();}
function musicStop(e:MouseEvent){channel.stop(); SoundMixer.stopAll();}
function musicEnd(e:Event){trace("soundEnd!!!");channel.stop();}
//TXT 불러오기 -이 아래는 모두 일반 Loader가 아닌 URLLoader를 사용.
var txtUrl:String = "loaderTest.txt";
var txtURLreq:URLRequest = new URLRequest(txtUrl);
var txtLoader:URLLoader = new URLLoader();
txtLoader.load(txtURLreq);
txtLoader.addEventListener(Event.COMPLETE, txtLoadComplete);
function txtLoadComplete(e:Event){
var str:String = e.target.data;
str = str.replace(/\r/g, "");
//정규표현식이용해 바꾸기
textBox1.txt.text = str;
trace("TXT Loading Complete");
}
//TXT 변수형태로 불러오기 -txt파일은 var1=34&var2=testing
형태로 구성
var txtUrl2:String = "loaderTestVar.txt";
var txtURLreq2:URLRequest = new URLRequest(txtUrl2);
var txtLoader2:URLLoader = new URLLoader();
txtLoader2.load(txtURLreq2);
txtLoader2.addEventListener(Event.COMPLETE, txtLoadComplete2);
function txtLoadComplete2(e:Event){
var vars:URLVariables = new URLVariables(e.target.data);
textSmall1.txt.text = vars.var1;
textSmall2.txt.text = vars.var2;
textSmall3.txt.text = vars.var3;
trace("TXT variables Loading Complete");
}
//XML 불러오기
var xmlUrl:String = "loaderTest.xml";
var xmlURLreq:URLRequest = new URLRequest(xmlUrl);
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(xmlURLreq);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoadComplete);
function xmlLoadComplete(e:Event){
var xmlVars:XML = new XML(e.target.data);
textBox2.txt.text = xmlVars;
trace("XML Loading Complete");
}
|