Flash AS教程_Flash按钮点击加载动态文本源码教程
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.SimpleButton;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
/**
* ...
* @author Main
*/
public class About extends MovieClip
{
private var Btnrq:Sprite = new Sprite();
private var wenz:Array = new Array({word:'a',lab:'1.txt'}, {word:'b,lab:'2.txt'}, {word:'c,lab:'3.txt'},{word:'4',lab:'4.txt'});
private var txturlloader:URLLoader = new URLLoader();
private var txturlrq:URLRequest=new URLRequest("1.txt");
private var len:int = wenz.length;
private var ID:int;
public function About()
{
txturlloader.load(txturlrq);
txturlloader.addEventListener(Event.COMPLETE,loaded);
for (var i:int = 0; i <len; i++)
{
var btn:Btn = new Btn();
btn.y = i * (btn.height + 5);
btn.ID = i;
btn.w_mc.word_txt.text = wenz[i].word;
btn.w_mc.bottonMode = true;
Btnrq.addChild(btn);
}
this.addChild(Btnrq);
Btnrq.x = word_mc.x +(Btnrq.width +20);
Btnrq.y = word_mc.height +(Btnrq.y + 10 );
btn.addEventListener(MouseEvent.CLICK, clickFn);
}
private function loaded(e:Event):void
{
about_txt.text = txturlloader.data;
}
private function clickFn(e:MouseEvent):void
{
var cur:Btn = e.currentTarget as Btn;
txturlrq.url = wenz[cur.ID].lab;
txturlloader.load(txturlrq);
}
}
}