close

範例: 網路速度要慢一點才看的到中間的Loading bar

http://mcr.tw/stu/gjun/carino/%E7%94%B1AS%E6%96%B0%E5%A2%9E%E7%9A%84%E6%8C%89%E9%88%95%E4%B8%94%E6%8C%89%E9%88%95%E6%9C%83%E6%8F%9B%E9%A1%8F%E8%89%B2/%E8%BC%89%E5%85%A5xml%E6%AA%94+%E6%8C%89%E9%88%95%E6%9C%83%E6%8F%9B%E9%A1%8F%E8%89%B2+%E8%BC%89%E5%85%A5%E9%80%B2%E5%BA%A62.swf

 

檔案下載(ADOBE CS5): http://www.filedropper.com/file_98

 

AS3:

主要的語法用紅色標記

 

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Loader;
stop();
var ldr:URLLoader = new URLLoader ;
var path:URLRequest = new URLRequest ;
var ldr2:Loader = new Loader ;
var path2:URLRequest = new URLRequest ;


//載入進度
ldr2.addEventListener(Event.ENTER_FRAME,_ENTERFRAME);//ldr2換成this也可以
ldr2.contentLoaderInfo.addEventListener(Event.COMPLETE,_COMPLETE);

function _ENTERFRAME(e:Event)
{
var percent:int = ldr2.contentLoaderInfo.bytesLoaded / ldr2.contentLoaderInfo.bytesTotal * 100;
t1.text = String(percent);
bar.scaleX = percent / 100;
}
function _COMPLETE(e:Event)
{
stage.addChildAt(ldr2,1);
}
//

//以AS呼叫出舞台上的元件
for (var i:uint=1; i<21; i++)
{
var button:MovieClip = new btn ;
button.x = i * 25 - 23;
button.y = 6;
button.buttonMode = true;
button.stop();
button.txt.text = i;
button.name = "b" + i;
stage.addChild(button);
button.addEventListener(MouseEvent.CLICK,_CLICK);
button.addEventListener(MouseEvent.MOUSE_OVER,_OVER);
button.addEventListener(MouseEvent.MOUSE_OUT,_OUT);
}
//

//選單按了變色,且作用的選單滑出滑入都沒作用
function _CLICK(e:MouseEvent)
{
stage.removeChild(ldr2);
var xml:XML = new XML(ldr.data);
txt.text = xml['dog']['name'][e.currentTarget.name.substr(1,2) - 1];
path2.url = xml['dog']['pic'][e.currentTarget.name.substr(1,2) - 1];
ldr2.load(path2);
stage.addChildAt(ldr2,0);
for (i=1; i<=20; i++)
{
MovieClip(stage.getChildByName(("b" + i))).gotoAndStop(1);
stage.getChildByName(("b" + i)).addEventListener(MouseEvent.MOUSE_OUT,_OUT);
}


e.currentTarget.gotoAndStop(3);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT,_OUT);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER,_OVER);
}
//

//選單滑入變色,滑出變回原來的顏色
function _OVER(e:MouseEvent)
{
e.currentTarget.gotoAndStop(2);
}
function _OUT(e:MouseEvent)
{
e.currentTarget.gotoAndStop(1);
}
//

//由XML載入資料
path.url = "dog/dog.xml";
ldr.load(path);
ldr.addEventListener(Event.COMPLETE,Fn);
function Fn(e:Event)
{
var xml:XML = new XML(ldr.data);
txt.text = xml['dog']['name'][0];
path2.url = xml['dog']['pic'][0];
ldr2.load(path2);

stage.addChildAt(txt,2);
}
//

 

arrow
arrow

    mosquitoyo 發表在 痞客邦 留言(0) 人氣()