dynamic flash xml news----滚动新闻
生活随笔
收集整理的這篇文章主要介紹了
dynamic flash xml news----滚动新闻
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
今天有人問起這個問題,抽出晚上的一點時間,做了一個,時間緊難免有不足之處,如果發(fā)現(xiàn)bug,請以在貼出。
演示:
代碼:
代碼://copyright by webstudio.com.cn 2005-4-7 system.useCodepage=true; Stage.scaleMode = "noscale"; // -- 繪制矩形 MovieClip.prototype.drawrect = function(pos_x, pos_y, w, h) { // -- this.px = pos_x; this.py = pos_y; this.an = w; this.al = h; // -- with (this) { beginFill(0xffffff, 20); moveTo(px, py); lineTo(px+an, py); lineTo(px+an, py+al); lineTo(px, py+al); lineTo(px, py); endFill(); } }; // -- 創(chuàng)建按扭點擊事件 xmlBinding = function (xmlObj) { this = xmlObj; var xpos = 0; for (var i = 0; i<this.firstChild.childNodes.length; i++) { item = newsTiker_mc.attachMovie("tiker_mc", "tiker"+i, 100+i); item.texto.autoSize = true; item.texto.text = this.firstChild.childNodes[i].attributes.mytext; item.mylink = this.firstChild.childNodes[i].attributes.links; item.texto.setTextFormat(myFormat); item._x = xpos; xpos += item.texto.textWidth+20; // -- item.onRelease = function() { this.texto.textColor = 0x666666; // -- 點擊打開鏈接 getURL(this.mylink, target="_blank"); }; // -- item.onRollOver = function() { this.texto.textColor = 0x000066; // -- 清除輪詢停止移動 clearInterval(idInterval); }; // -- item.onRollOut = function() { this.texto.textColor = 0x333333; // -- 重新輪詢,繼續(xù)移動 idInterval = setInterval(scrollit, 10, this._parent); }; } }; // -- 滾動定義 scrollit = function (myclip) { myclip._x -= 1; updateAfterEvent(); // -- 點擊測試 if (!myclip.hitTest(maskTiker)) { myclip._x = maskTiker._x+maskTiker._width; } }; // -- 格式化文本 myFormat = new TextFormat(); //myFormat.font = "harmony"; myFormat.size = 12; myFormat.color = 0x333333; // -- 載入xml myXML = new XML(); myXML.ignoreWhite = true; myXML.onLoad = function(succes) { if (succes) { xmlBinding(this); } else { trace("Error cannot load xml"); } }; myXML.load("news.xml"); // -- 創(chuàng)建遮罩 this.createEmptyMovieClip("maskTiker", this.getNextHighestDepth()); this.maskTiker.drawrect(newsTiker_mc._x, newsTiker_mc._y, 360, 20); newsTiker_mc.setMask(this.maskTiker); // -- 開始輪詢 idInterval = setInterval(scrollit, 10, newsTiker_mc);
后端載入news.xml
如有問題請貼出,另外看你能不能做出一個v-scroll xml news,當前我這個可是個h-scroll xml news 上傳的附件
演示:
代碼:
代碼://copyright by webstudio.com.cn 2005-4-7 system.useCodepage=true; Stage.scaleMode = "noscale"; // -- 繪制矩形 MovieClip.prototype.drawrect = function(pos_x, pos_y, w, h) { // -- this.px = pos_x; this.py = pos_y; this.an = w; this.al = h; // -- with (this) { beginFill(0xffffff, 20); moveTo(px, py); lineTo(px+an, py); lineTo(px+an, py+al); lineTo(px, py+al); lineTo(px, py); endFill(); } }; // -- 創(chuàng)建按扭點擊事件 xmlBinding = function (xmlObj) { this = xmlObj; var xpos = 0; for (var i = 0; i<this.firstChild.childNodes.length; i++) { item = newsTiker_mc.attachMovie("tiker_mc", "tiker"+i, 100+i); item.texto.autoSize = true; item.texto.text = this.firstChild.childNodes[i].attributes.mytext; item.mylink = this.firstChild.childNodes[i].attributes.links; item.texto.setTextFormat(myFormat); item._x = xpos; xpos += item.texto.textWidth+20; // -- item.onRelease = function() { this.texto.textColor = 0x666666; // -- 點擊打開鏈接 getURL(this.mylink, target="_blank"); }; // -- item.onRollOver = function() { this.texto.textColor = 0x000066; // -- 清除輪詢停止移動 clearInterval(idInterval); }; // -- item.onRollOut = function() { this.texto.textColor = 0x333333; // -- 重新輪詢,繼續(xù)移動 idInterval = setInterval(scrollit, 10, this._parent); }; } }; // -- 滾動定義 scrollit = function (myclip) { myclip._x -= 1; updateAfterEvent(); // -- 點擊測試 if (!myclip.hitTest(maskTiker)) { myclip._x = maskTiker._x+maskTiker._width; } }; // -- 格式化文本 myFormat = new TextFormat(); //myFormat.font = "harmony"; myFormat.size = 12; myFormat.color = 0x333333; // -- 載入xml myXML = new XML(); myXML.ignoreWhite = true; myXML.onLoad = function(succes) { if (succes) { xmlBinding(this); } else { trace("Error cannot load xml"); } }; myXML.load("news.xml"); // -- 創(chuàng)建遮罩 this.createEmptyMovieClip("maskTiker", this.getNextHighestDepth()); this.maskTiker.drawrect(newsTiker_mc._x, newsTiker_mc._y, 360, 20); newsTiker_mc.setMask(this.maskTiker); // -- 開始輪詢 idInterval = setInterval(scrollit, 10, newsTiker_mc);
后端載入news.xml
如有問題請貼出,另外看你能不能做出一個v-scroll xml news,當前我這個可是個h-scroll xml news 上傳的附件
| flashxmlnews.rar (8.0 KB, 636次查看) |
轉(zhuǎn)載于:https://www.cnblogs.com/savageworld/archive/2006/07/29/462782.html
總結(jié)
以上是生活随笔為你收集整理的dynamic flash xml news----滚动新闻的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Intel (Altera) LVDS
- 下一篇: 如何录制电脑系统声音(Audacity)