图片已经运动起来了,但我们需要的效果能不能让鼠标发生触发事情呢?
答案是肯定的:可以
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Loader;
import flash.events.*;
import flash.utils.*;//执行时间间隔的
import flash.net.*;
import flash.system.System;
public class Picture extends MovieClip {
private var tempMC:mc;
private var movetime:Timer;
private var picArray:Array;//装载多个影片剪辑的
private var imgArray:Array;//装载多个loader 对象
private var list:Array;
private var myxml:XML;
private var mylist:XMLList;
private var ld:Loader;
private var _loader:URLLoader;
private var myurl:URLRequest;
public function Picture() {
System.useCodePage=true;
picArray=new Array();
imgArray=new Array();
list=new Array();
myxml=new XML();
myxml.ignoreWhite = true;
_loader=new URLLoader();
_loader.load(new URLRequest("menu.XML"));
_loader.addEventListener(Event.COMPLETE,loading);
for (var i:int=0; i<7; i++) {
tempMC = new mc();
tempMC.addEventListener(MouseEvent.MOUSE_OVER,stoping);//产生鼠标事件
tempMC.addEventListener(MouseEvent.MOUSE_OUT,starting);//产生鼠标事件
picArray.push(tempMC);
addChild(picArray[i]);
picArray[i].x=i*picArray[i].width;
}
movetime=new Timer(80);
movetime.addEventListener(TimerEvent.TIMER,picmove);
movetime.start();
}
private function picmove(event:TimerEvent):void {
for (var t:int=0; t<7; t++) {
picArray[t].x-=5;
if (picArray[t].x<-88) {
picArray[t].x=6*88;
}
}
}
private function loading(evt:Event):void {
myxml=XML(_loader.data);
mylist=myxml.children();
trace( mylist);
for (var j:int=0; j<mylist.length(); j++) {
list[j]=mylist.attribute("url")[j];
trace(list[j]);
ld=new Loader();//加载图片用
imgArray.push(ld);//管理多个loader 对象
imgArray[j].load(new URLRequest(list[j]));
picArray[j].addChild(imgArray[j]);
}
}
private function stoping(e:MouseEvent):void {
movetime.stop();//停止图片运动
}
private function starting(e:MouseEvent):void {
movetime.start();//让图片开始运动
}
}
}