论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash教程
Tag:flash cs,flash 8,鼠绘,as,手绘,工具,文字,loading,入门,初学,mc,影片剪辑,声音,mtv,游戏,引导,遮罩,菜单,补间,广告条,时钟,视频教程

as3.0动态读取xml文件的焦点图

文章类别:Flash | 发表日期:2010-1-31 14:24:20

全部代码:

代码:
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);
上一篇:{教程}图片运动的效果 人气:4768
下一篇:{教程}FLASH获取当前网页URL的方法 人气:3019
视频教程列表
文章教程搜索
 
Flash推荐教程
Flash热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058