1
2
2.建一个example.as和pic文件夹,文件夹里放三张图,命名为pic1,pic2,pic3example.as的代码如下:package {import flash.display.Sprite;import flash.events.MouseEvent;import fl.controls.CheckBox;import fl.controls.ColorPicker;import fl.controls.ComboBox;import fl.controls.Slider;import flash.text.TextField;import flash.display.Graphics;import flash.events.Event;import flash.display.Shape;import fl.events.SliderEvent;import flash.net.URLRequest;import flash.net.URLLoader;import flash.display.Loader;public class example extends Sprite { var ck:CheckBox; var cp:ColorPicker; var sl:Slider; var cb:ComboBox; var tf1:TextField; var tf2:TextField; var sp:Loader; var color:int=0x000000; var xmloader:URLLoader; var xml:XML; var xmlList:XMLList; var rec:Shape=new Shape; public function example() { drawrec(); creatck(); creatcp(); creatsl(); creatcb(); creatsp(); } function creatsl() { sl=new Slider ; sl.move(48,150); sl.maximum=1; sl.minimum=0; sl.snapInterval=0.1; sl.tickInterval=0.1; addChild(sl); sl.addEventListener(SliderEvent.CHANGE,sliderChanged); } function sliderChanged(e:SliderEvent):void { rec.alpha=sl.value; } function creatsp() { xmloader=new URLLoader(); var request:URLRequest=new URLRequest("data.xml"); xmloader.load(request); xmloader.addEventListener(Event.COMPLETE, sploaded); } function sploaded(e:Event):void { xml = XML(e.target.data); xmlList = xml.children(); sp = new Loader(); sp.x=230; sp.y=60; sp.load(new URLRequest(xmlList[0].attribute("source"))); addChild(sp); } function drawrec() { rec.graphics.beginFill(color); rec.graphics.drawRect(220,50,450,335); rec.graphics.endFill(); } function creatck() { ck=new CheckBox ; ck.label="显示背景"; ck.move(40,66); addChild(ck); ck.addEventListener(MouseEvent.CLICK,ckclick); } function ckclick(e:MouseEvent):void { if (ck.selected) { addChildAt(rec,0); } else { removeChild(rec); } } function creatcp() { cp=new ColorPicker ; cp.move(44,96); addChild(cp); cp.addEventListener(Event.RENDER,colorChange); } function colorChange(e:Event):void { rec.graphics.clear(); color=cp.selectedColor; drawrec(); } function creatcb() { cb=new ComboBox(); cb.addItem({label:"pic1"}); cb.addItem({label:"pic2"}); cb.addItem({label:"pic3"}); cb.move(45,200); addChild(cb); cb.addEventListener(Event.CHANGE,picchange); } function picchange(e:Event):void { if (cb.selectedItem.label=="pic1") { sp.load(new URLRequest(xmlList[0].attribute("source"))); } if (cb.selectedItem.label=="pic2") { sp.load(new URLRequest(xmlList[1].attribute("source"))); } if (cb.selectedItem.label=="pic3") { sp.load(new URLRequest(xmlList[2].attribute("source"))); } }}}
没有评论:
发表评论