做了个不太一样的跑马灯,你可以左右移动鼠标控制运动方向和速度。点击这里查看效果。代码如下:

/***************import classes***************/

import mx.transitions.*; 

/*********declare variables and instances*******/ 

var nextX = 0; 

var num = 7; 

var speed = 2; 

/****************create objects**************/ 

var initThumb:Object = new Object(); 

/****************handle events**************/ 

this.createEmptyMovieClip("mcScroller", this.getNextHighestDepth()); 

mcScroller._x = 0; 

mcScroller._y = 20; 

mcScroller.onEnterFrame = function() { 

this._x -= speed; 

if(this._x>0||this._x<Stage.width-this._width){ 

speed *= -1; 

}; 

for (i=0; i<7; i++) { 

thumbName = "mcThumb"+i; 

newThumb = mcScroller.attachMovie("thumbs", thumbName, i, initThumb); 

newThumb.photo.attachMovie("p"+i, p, i); 

newThumb._x = nextX; 

newThumb._y = 0; 

newThumb._alpha = 50; 

nextX += 120; 

setInterval(_root, "scroller", 50); 

/******************functions****************/ 

function scroller() { 

if (this._ymouse>mcScroller._y) { 

var scrollSpeed = (this._xmouse-Stage.width/2)/10; 

mcScroller._x -= scrollSpeed; 

if (Math.abs(scrollSpeed)<5) { 

scrollSpeed = 0; 

if (mcScroller._x>0) { 

mcScroller._x = 0; 

} else if (mcScroller._x<Stage.width-mcScroller._width) { 

mcScroller._x = Stage.width-mcScroller._width; 

在这里,使用的是库中的图像(保存在p1到p7的mc中),当然也可使用xml对象进行动态设置来调取外部图像文件。而且,你也可以在其中加入一些链接之类的内容。