全部代码:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.MovieClip;
var image_box:Sprite = new Sprite();
var image_show:Sprite = new Sprite();
var txtMc:Sprite = new Sprite();
var txtOne:TextField = new TextField();
var txtTwo:TextField = new TextField();
var txtThree:TextField = new TextField();
var txtFour:TextField = new TextField();
var folder:String = "focus/";
var arrImg:Array = new Array();
var arrBtn:Array = new Array();
var arrTxt:Array = new Array();
var arrUrl:Array = new Array();
var btnOuter:btn_box = new btn_box();
var time:Timer = new Timer(3000);
var j:int = 0;
//myXML load
var myXML:XML = new XML();
var XML_URL:String = "focus/focus_data.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(evtObj:Event) {
myXML = XML(myLoader.data);
for (var i:int = 0; i<myXML.thumbnail.length(); i++) {
arrImg.push(folder + myXML.thumbnail[i].filename);
arrTxt.push(myXML.thumbnail[i].titles);
arrUrl.push(myXML.thumbnail[i].url);
var btn:Sprite = new Sprite();
arrBtn.push(btn);
btn.graphics.drawRect(0,0,20,20);
btn.x = 230 + 30 * i;
btn.y = 2;
btn.buttonMode = true;
btn.mouseChildren=false;
btn.name = i.toString();
btn.addEventListener( MouseEvent.CLICK, btn_click );
var btnTxt:TextField = new TextField();
btnTxt.wordWrap=true;
btnTxt.width = 20;
btnTxt.height = 20;
btnTxt.background = true;
btnTxt.backgroundColor = 0xD4DEE0;
btnTxt.text = (i+1).toString();
btnTxt.setTextFormat(getFormat());
btnOuter.addChild(btn);
btn.addChild(btnTxt);
}
bigImgShow(0);//默认显示
btnAutoShow(0);//默认显示
}
function btn_click(me:MouseEvent) {
var s_no:Number = me.currentTarget.name;
time.stop();
time.start();
j = s_no;
bigImgShow(s_no);
btnAutoShow(s_no);
}
function getFormat():TextFormat {
var myFmt:TextFormat=new TextFormat;
myFmt.align="center";
myFmt.bold=true;
myFmt.font="方正粗宋简体";
myFmt.size=12;
myFmt.color=0x4EA4A3;
return myFmt;
}
function getFormatOver():TextFormat {
var myFmt:TextFormat=new TextFormat;
myFmt.color=0xffffff;
return myFmt;
}
function btn_Over(btnObj:Sprite) {
var btnObjTxt:TextField = btnObj.getChildAt(0) as TextField;
btnObjTxt.setTextFormat(getFormatOver());
btnObjTxt.backgroundColor = 0xD7CC25;
}
function btn_Out(btnObj:Sprite) {
var btnObjTxt:TextField = btnObj.getChildAt(0) as TextField;
btnObjTxt.setTextFormat(getFormat());
btnObjTxt.backgroundColor = 0xD4DEE0;
}
function onTimer(e:TimerEvent):void {
j++;
if (j==arrImg.length) {
j = 0;
removeEventListener(TimerEvent.TIMER,onTimer);
}
bigImgShow(j);
btnAutoShow(j);
}
//btn auto show
function btnAutoShow(index:int) {
for (var m:int; m<arrBtn.length; m++) {
if (arrBtn[index]!=arrBtn[m]) {
btn_Out(arrBtn[m]);
}
}
btn_Over(arrBtn[index]);
}
//images show And txt
function bigImgShow(index:int) {
var ldr:Loader = new Loader();
var urlReq:URLRequest = new URLRequest(arrImg[index]);
ldr.load(urlReq);
txtOne.text = arrTxt[index].txt[0].toString();
txtTwo.text = arrTxt[index].txt[1].toString();
txtThree.text = arrTxt[index].txt[2].toString();
txtFour.text = arrTxt[index].txt[3].toString();
txtOne.setTextFormat(getFormatOver());
txtTwo.setTextFormat(getFormatOver());
txtThree.setTextFormat(getFormatOver());
txtFour.setTextFormat(getFormatOver());
var myTween:Tween = new Tween(txtMc, "y", Elastic.easeOut, 490, 480, 3, true);
var txt_blur:BlurFilter = new BlurFilter(0, 0, 0);
txtOne.filters = [txt_blur];
txtTwo.filters = [txt_blur];
txtThree.filters = [txt_blur];
txtFour.filters = [txt_blur];
var myTweenTxt:Tween = new Tween(txtMc, 'alpha', Strong.easeOut, 0, 1, 1, true);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,comPleteHandler);
//控制图片比例显示
function comPleteHandler(e:Event) {
var bp:Bitmap = (ldr.content as Bitmap);
if (bp.width > image_box.width && bp.height > image_box.height && bp.width > bp.height) {
bp.width = image_box.width;
bp.scaleY = bp.scaleX;
}
if (bp.width > image_box.width && bp.height > image_box.height && bp.width < bp.height) {
bp.height = image_box.height;
bp.scaleX = bp.scaleY;
}
if (bp.width > image_box.width) {
bp.width = image_box.width;
bp.scaleY = bp.scaleX;
}
if (bp.height > image_box.height) {
bp.height = image_box.height;
bp.scaleX = bp.scaleY;
}
if (bp.width > image_box.width) {
bp.width = 2 * image_box.width - bp.width;
bp.scaleY = bp.scaleX;
}
if (bp.height > image_box.height) {
bp.height = 2 * image_box.height - bp.height;
bp.scaleX = bp.scaleY;
}
image_show.x = (image_box.width - bp.width)/2;
image_show.y = (image_box.height - bp.height)/2;
if (image_show.numChildren == 1) {
image_show.removeChildAt(0);
}
var image_tw:Tween = new Tween(image_show, 'alpha', Strong.easeOut, 0, 1, 0.8, true);
image_show.addChild(ldr);
image_show.buttonMode = true;
image_show.addEventListener(MouseEvent.MOUSE_DOWN,linkUrl);
function linkUrl(e:Event) {
var url:String = arrUrl[index].toString();
navigateToURL(new URLRequest(url),"_balnk");
}
}
}
image_box.graphics.beginFill(0xffffff);
image_box.graphics.drawRect(0,0,388,454);
image_box.x = 0;
image_box.y = 0;
btnOuter.x = 12.5;
btnOuter.y = 425;
txtOne.x = 9;
txtOne.y = -20;
txtTwo.x = 208;
txtTwo.y = -20;
txtThree.x = 9;
txtThree.y = 0;
txtFour.x = 208;
txtFour.y = 0;
txtMc.x = 0;
txtMc.y = 40;
txtMc.x = 0;
txtMc.y = 480;
time.addEventListener(TimerEvent.TIMER,onTimer);
time.start();
addChild(image_box);
image_box.addChild(image_show);
addChild(btnOuter);
addChild(txtMc);
txtMc.addChild(txtOne);
txtMc.addChild(txtTwo);
txtMc.addChild(txtThree);
txtMc.addChild(txtFour);
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |