<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" verticalScrollPolicy="off" creationComplete="init()" layout="absolute"> <mx:Script> <!--[CDATA[ import mx.controls.Button; import mx.controls.Text; import mx.containers.HBox; import mx.controls.Alert; import mx.controls.Image; import mx.containers.Canvas; import mx.core.Container; private var _url:String="moveImage2.xml"; private var _width:int; private var _height:int; private var _time:int; //动画间隔 private var _displayImageWidth:int; //大屏显示时的宽度 private var _displayImageHeight:int; private var _normalImageWidth:int; //正常宽度 private var _normalImageHeight:int; private var _pitch:int=10; private var _showAlignment:String="left"; private var _X:int=0; private var _XS:int=0; private var _imageArray:Array=new Array; private var _moveUp:Array=new Array; //需要滚动的图片数组 private var _moveDown:Array=new Array; //横向要移动的图片数组 private var _timeLine:Timer; private var _farmTime:Timer; private var _frameTime:int=100; //每帧的动画时间 private var _clickImageArrayNum:int=0; private var _clickImage:Iimage; private var _currentShowImage:Iimage; private var _currentCount:int=0; private var _clickNum:int=1; private var _isplay:Boolean=false; var bColorss:Array=["",""]; public function initApp():void { ExternalInterface.addCallback("getValite",init); } private function init():void{ // this._url=url; try{ var req:URLRequest=new URLRequest(_url); new URLLoader(req) .addEventListener(Event.COMPLETE, function(event : Event) : void { var s:String=event.currentTarget.data; var example:XML = new XML(s); _width=example.@width; _height=example.@height; _time=example.@timer; _displayImageWidth=example.@displayImageWidth; _displayImageHeight=example.@displayImageHeight; _normalImageWidth=example.@normalImageWidth; _normalImageHeight=example.@normalImageHeight; _showAlignment=example.@alignment; bColorss[0]=example.@BackgroundColorStar; bColorss[1]=example.@BackgroundColorEnd; _imageArray=ElementToAttr2(example.children()); initImage(); } ); }catch(error:Error){ Alert.show("网络连接出错!"); } } private function initImage():void{ this.width=_width; this.height=_height; this.setStyle("backgroundGradientColors",bColorss); if(_showAlignment=="left"){ _X=_pitch; _XS=3*_pitch+_normalImageWidth; } else if(_showAlignment=="right"){ _X=2*_pitch+_displayImageWidth; _XS=0; } for(var i:int=0;i<_imageArray.length;i++){ _imageArray[i].width=_normalImageWidth; _imageArray[i].height=_normalImageHeight; _imageArray[i].y=i*(_normalImageHeight+_pitch)-_normalImageHeight; _imageArray[i].x=_X; _imageArray[i].alpha=1.5; _imageArray[i].addEventListener(MouseEvent.CLICK,mouseClick); this.addChild(_imageArray[i]); } _currentShowImage=_imageArray[0]; _currentShowImage.alpha=1.5; _currentShowImage.width=_displayImageWidth; _currentShowImage.height=_displayImageHeight; _currentShowImage.y=_pitch; _currentShowImage.x=_XS; var sor:Image=new Image(); sor.alpha=1.5; sor.source="img/0.jpg"; sor.x=_X; sor.y=3*(_normalImageHeight+_pitch)+_pitch; sor.height=_normalImageHeight/2; sor.width=_normalImageWidth; this.addChild(sor); sor.addEventListener(MouseEvent.CLICK ,clickNext); _clickImage=_imageArray[1]; _farmTime=new Timer(_time,0); _timeLine=new Timer(30,0); _farmTime.start(); check(); _farmTime.addEventListener(TimerEvent.TIMER,autoMobile); _timeLine.addEventListener(TimerEvent.TIMER,moveLineImage); } private function mouseClick(event:MouseEvent):void{ var imgs:Iimage=(event.currentTarget as Iimage); if(imgs.Iid==_currentShowImage.Iid){ var request:URLRequest = new URLRequest(_currentShowImage.url); navigateToURL(request,'_blank'); }else{ if(!_isplay){ if(_moveDown.length>0){ _moveDown.splice(0,_moveDown.length); _moveDown=new Array(); } if(_moveUp.length>0){ _moveUp.splice(0,_moveUp.length); _moveUp=new Array(); } _clickImage=imgs; var _i:int=_clickImage.Iid; _clickNum=_i; for(var i:int=0;i<_imageArray.length;i++){ if(_imageArray[i].y<_imageArray[_i].y&&i!=_currentShowImage.Iid){ _moveDown.push(_imageArray[i]); }else if(_imageArray[i].y>_imageArray[_i].y&&i!=_currentShowImage.Iid){ _moveUp.push(_imageArray[i]); } } _moveDown.sortOn("y",4); _moveUp.sortOn("y",4); _farmTime.stop(); _timeLine.start(); _isplay=true; } } } private function moveLineImage(event:Event):void{ _currentCount++; for(var i:int=0;i<_moveUp.length;i++){ _moveUp[i].y-=(_normalImageHeight+_pitch)*(_moveDown.length+1)/10; } for(var j:int=0;j<_moveDown.length;j++){ _moveDown[j].y+=(_moveUp.length)*(_normalImageHeight+_pitch)/10; } _clickImage.width+=(_displayImageWidth-_normalImageWidth)/10; _clickImage.height+=(_displayImageHeight-_normalImageHeight)/10; _clickImage.x+=(_XS-_X)/10; _clickImage.y-=(_moveDown.length)*(_normalImageHeight+_pitch)/10; _currentShowImage.width-=(_displayImageWidth-_normalImageWidth)/10; _currentShowImage.height-=(_displayImageHeight-_normalImageHeight)/10; _currentShowImage.x-=(_XS-_X)/10; _currentShowImage.y+=(_moveUp.length+_moveDown.length)*(_normalImageHeight+_pitch)/10; if(_currentCount==10){ _currentShowImage=_clickImage; _timeLine.stop(); _currentCount=0; _isplay=false; _clickNum++; if(_clickNum>=_imageArray.length){ _clickNum=0; } _farmTime.start(); check(); } } private function autoMobile(event:Event):void{ moveImage2(); } public function clickNext(event:MouseEvent):void{ _farmTime.stop(); moveImage2(); } public function check():void{ for(var i:int=0;i<_imageArray.length;i++){ if((_imageArray[i].y+_imageArray[i].height)>this.height){ _imageArray[i].visible=false; }else{ _imageArray[i].visible=true; } } } public function moveImage2():void{ if(_moveDown.length>0){ _moveDown.splice(0,_moveDown.length); _moveDown=new Array(); } if(_moveUp.length>0){ _moveUp.splice(0,_moveUp.length); _moveUp=new Array(); } _isplay=true; var _minImageY:Iimage=_imageArray[_clickNum]; for(var ii:int=0;ii<_imageArray.length;ii++){ if(_imageArray[ii].Iid!=_currentShowImage.Iid&&_imageArray[ii].y<=_minImageY.y){ _minImageY=_imageArray[ii]; } } _clickImage=_minImageY; var _i:int=_clickImage.Iid; for(var i:int=0;i<_imageArray.length;i++){ if(_imageArray[i].y<_imageArray[_i].y&&i!=_currentShowImage.Iid){ _moveDown.push(_imageArray[i]); }else if(_imageArray[i].y>_imageArray[_i].y&&i!=_currentShowImage.Iid){ _moveUp.push(_imageArray[i]); } } _moveDown.sortOn("y",4); _moveUp.sortOn("y",4); _timeLine.start(); } //属性形式的XML public function ElementToAttr2(results:XMLList):Array { var array:Array=new Array(); var k:int=0; for each(var child:XML in results){ var obj:Iimage=new Iimage(); var attNamesList:XMLList = child.@*; for(var i:int=0;i<attNamesList.length();i++) { obj[attNamesList[i].name().toString()]=attNamesList[i].toString(); } obj.Iid=k; array.push(obj); k++; } return array; } ]]--> </mx:Script> </mx:Application> 演示地址: http://www.lvwlv.com/showModel/move.html