自己做着玩的,有需要的朋友可以点击下载源文件: 下拉条源文件
AS-CODE:
package { import flash.display.MovieClip; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.display.StageDisplayState; import flash.events.Event; import flash.events.MouseEvent; import flash.net.navigateToURL; import flash.display.Sprite; import flash.geom.Rectangle; import flash.text.TextField; import flash.text.TextFormat; import flash.text.TextFieldAutoSize; import flash.net.URLRequest; public class Main extends MovieClip { private var girlMc:MovieClip; private var scrollMc:Scroll; private var maskMc:MovieClip; private var mc:MovieClip; private var myTxt:TextField; private var myFormat:TextFormat; private var girlNum:int = 1; private var x1; private var y1; private var h1; public function Main():void { if (stage) { Init(null); } else { addEventListener(Event.ADDED_TO_STAGE,Init); } } private function Init(e:Event=null) { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; var leftFun=new LeftFun(this); mc=new MovieClip(); girlMc=new MovieClip(); maskMc=new MovieClip(); addChild(mc); addChild(girlMc); addChild(maskMc); layElement(); } private function layElement() { resetGirl(girlNum); girlMc.buttonMode = true; girlMc.addEventListener(MouseEvent.CLICK,clickHandler); scrollMc=new Scroll(); scrollMc.x = girlMc.width + 15; addChild(scrollMc); maskMc.graphics.beginFill(0x00ff00,0.3); maskMc.graphics.drawRect(0,0,girlMc.width,scrollMc.height); maskMc.graphics.endFill(); maskMc.x = 0; maskMc.y = 0; girlMc.mask = maskMc; for (var i:int=0; i<2; i++) { var mc2=new Mc2(); if (i==1) { mc2.rotation = 180; mc2.y = mc2.height / 2 + scrollMc.height + mc2.height; mc2.x = 60 + mc2.width; } else { mc2.y = - mc2.height / 2 + scrollMc.height + mc2.height; mc2.x = maskMc.width - 60 - mc2.width; } mc.addChild(mc2); mc2.buttonMode = true; mc2.name = i; mc2.addEventListener(MouseEvent.ROLL_OVER,mcOverHandler); mc2.addEventListener(MouseEvent.ROLL_OUT,mcOutHandler); mc2.addEventListener(MouseEvent.CLICK,clickHandler); } myTxt=new TextField(); myTxt.autoSize = TextFieldAutoSize.LEFT;//有了这句,文字才会显示完全 myTxt.width = 310; myTxt.multiline = true; myTxt.wordWrap = true; myFormat=new TextFormat(); myFormat.bold = true; myFormat.color = 0xff0000; myFormat.letterSpacing = 2; myFormat.size = 15; myTxt.text = "请点击舞台上的左右键,增减女孩数目.女孩现在的数目是" + girlNum + "个"; myTxt.setTextFormat(myFormat); myTxt.y = maskMc.y + maskMc.height + mc2.height - myTxt.textHeight / 2; myTxt.x = maskMc.width / 2 - myTxt.textWidth / 2; myTxt.mouseEnabled = false; mc.addChild(myTxt); x1 = scrollMc.width / 2 - scrollMc.bar.width / 2; y1 = scrollMc.mcScale.y; h1 = scrollMc.mcScale.height; mc.addChild(girlMc); mc.addChild(maskMc); mc.addChild(scrollMc); mc.x = stage.stageWidth / 2 - mc.width / 2; mc.y = stage.stageHeight / 2 - scrollMc.height / 2 - mc2.height / 2 - 10; mcEvent(); } private function mcOverHandler(e:MouseEvent) { e.target.gotoAndStop(5); } private function mcOutHandler(e:MouseEvent) { e.target.gotoAndStop(1); } private function resetGirl(num:int) { if (myTxt) { myTxt.text = "请点击舞台上的左右键,增减女孩数目.女孩现在的数目是" + num + "个"; myTxt.setTextFormat(myFormat); } while (girlMc.numChildren>0) { girlMc.removeChildAt(0); } for (var i:int=0; i<num; i++) { var girl=new Girl(); girl.x = 0; girl.y = i * girl.height; girlMc.addChild(girl); } } /** *下边这些才是下来条的功能部分,上边只是前奏。当被下拉剪辑的高度, *小于下拉条的高度的时候,下来条的下拉头最长。但是,最短设定为30了。可以任设置。 */ private function mcEvent() { scrollMc.bar.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler); scrollMc.bar.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler); stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler); scrollMc.bar.addEventListener(Event.ENTER_FRAME,enterHandler); scrollMc.btnUp.buttonMode = true; scrollMc.btnDown.buttonMode = true; scrollMc.btnUp.addEventListener(MouseEvent.CLICK,clickHandler); scrollMc.btnDown.addEventListener(MouseEvent.CLICK,clickHandler); stage.addEventListener(MouseEvent.MOUSE_WHEEL ,onMouseWheelHandler); } private function mouseDownHandler(e:MouseEvent) { scrollMc.bar.startDrag(false,new Rectangle(x1,y1,0,h1-scrollMc.bar.height)); } private function mouseUpHandler(e:MouseEvent) { scrollMc.bar.stopDrag(); } private function clickHandler(e:MouseEvent) { trace(e.target.name); switch (e.target.name) { case "btnUp" : scrollMc.bar.y -= 10; break; case "btnDown" : scrollMc.bar.y += 10; break; case "0" : girlNum++; if (girlNum>10) { girlNum = 10; } resetGirl(girlNum); break; case "1" : girlNum--; if (girlNum<0) { girlNum = 0; } resetGirl(girlNum); break; case "girlMc" : navigateToURL(new URLRequest("http://www.vini123.com/chatroom/"),"_blank"); break; } } private function onMouseWheelHandler(event:MouseEvent):void { var deltaNum:Number = event.delta; scrollMc.bar.y += event.delta * 2; } private function enterHandler(e:Event) { if (scrollMc.bar.y <= y1) { scrollMc.bar.y = y1; } if (scrollMc.bar.y >=(h1 + y1 - scrollMc.bar.height)) { scrollMc.bar.y = h1 + y1 - scrollMc.bar.height; } var _h1=(maskMc.height>girlMc.height?1:maskMc.height/girlMc.height)*h1; scrollMc.bar.height = _h1 < 30 ? 30:_h1; girlMc.y=int(scrollMc.bar.y-y1)*(maskMc.height-girlMc.height)/(h1-scrollMc.bar.height); } } //上边这个算法。记得这里girlMc的纵坐标是0.如果是不是0.还要加上纵坐标。就ok了。 }