讀取 外部 記事本資料

1.txt 、2.txt、 3.txt

●先建立一個 content 影片片段
●在 content 內 建立 旗標 p1 p2 p3
-------------------------------------------------------------
主場景第一格

stage.addEventListener(MouseEvent.CLICK,$click);


function $click(e:Event){
if(e.target==Home_btn){
content.gotoAndStop("p1");
}else if (e.target==Products_btn){
content.gotoAndStop("p2");
}else (e.target==Services_btn){
content.gotoAndStop("p3");
}
}

 


----------------------------------------------------------------

 

//元件程式

//第一格

stop();
System.useCodePage=true;
var myLoader1:URLLoader = new URLLoader(new URLRequest("1.txt"));

myLoader1.addEventListener(Event.COMPLETE, loadText);

myLoader1.addEventListener(IOErrorEvent.IO_ERROR,$error);
function loadText(e:Event):void {
monthNames.text = myLoader1.data;
}

function $error(e:Event):void {
monthNames.text = "檔案不存在";
}

-------------------------------------------------

//第五格

var myLoader2:URLLoader = new URLLoader(new URLRequest("2.txt"));
myLoader2.addEventListener(Event.COMPLETE, loadText2);
myLoader2.addEventListener(IOErrorEvent.IO_ERROR,$error);
function loadText2(e:Event):void {
monthNames.text = myLoader2.data;
}

-------------------------------------------------------
//第十格

var myLoader3:URLLoader = new URLLoader(new URLRequest("3.txt"));
myLoader3.addEventListener(Event.COMPLETE, loadText3);
myLoader3.addEventListener(IOErrorEvent.IO_ERROR,$error);
function loadText3(e:Event):void {
monthNames.text = myLoader3.data;
}
-------------------------------------------------------------

雞蛋貓異想世界 發表在 痞客邦 PIXNET 留言(0) 人氣()