flash 容器滚动效果

import flash.display.MovieClip; import flash.geom.Rectangle; import fl.controls.UIScrollBar; import fl.controls.ScrollBarDirection; import fl.events.ScrollEvent; var container:MovieClip=new MovieClip(); //container.addChild(create_mc()); //container.addChild(create_mc()); addChild(container); var p_x:uint=0; var p_y:uint=0; var rect:Rectangle=new Rectangle(0,0,60,60); container.scrollRect=rect; for(var i:uint=0;i<36;i++){ if(i%3==0){ p_x=0; if(i!=0){ p_y+=20; } } var mc:MovieClip=create_mc(); mc.x=p_x; mc.y=p_y; p_x+=20; container.addChild(mc); } //container.height=100; var scroll_bar:UIScrollBar=new UIScrollBar(); scroll_bar.direction=ScrollBarDirection.VERTICAL; scroll_bar.setScrollProperties(5,1,180); scroll_bar.addEventListener(ScrollEvent.SCROLL,scroll_handle); addChild(scroll_bar); scroll_bar.y=150; scroll_bar.x=150; function scroll_handle(evt:ScrollEvent):void{ //trace(evt.target.scrollPosition); var rect:Rectangle =container.scrollRect; rect.y=Math.floor(evt.target.scrollPosition); container.scrollRect=rect; } function create_mc():MovieClip{ var mc:MovieClip=new MovieClip(); mc.graphics.beginFill(0xFF0000,0.5); mc.graphics.drawCircle(10,10,10); mc.graphics.endFill(); return mc; }

你可能感兴趣的:(function,Flash,import,scroll)