赞
踩
下面是完整的代码,就不多说废话了。
package {
import com.greensock.layout.ScaleMode;
import com.greensock.loading.ImageLoader;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
public class scrollrectTest extends Sprite {
private var ldr:ImageLoader;
private var _mousePosition:Point;
private var _scenePosition:Point;
private var left:int = 0;
private var top:int = 0;
public function scrollrectTest() {
ldr = new ImageLoader('IMG_0943.JPG', {
name:'image',
container: this,
width: 800, height: 600,
scaleMode : ScaleMode.PROPORTIONAL_INSIDE,
requireWithRoot : root
});
ldr.load();
this.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
this.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
}
private function mouseUp(event:MouseEvent):void {
this._mousePosition = null;
}
private function mouseDown(event:MouseEvent):void {
this._mousePosition = new Point(event.stageX, event.stageY);
}
private function mouseMove(event:MouseEvent):void {
var pt:Point;
var child:DisplayObject;
child = this.getChildByName("image");
if (event.buttonDown && _mousePosition) {
pt = new Point(event.stageX, event.stageY);
pt = pt.subtract(this._mousePosition);
_mousePosition = new Point(event.stageX, event.stageY);
left = left - pt.x;
top = top - pt.y;
if (left < 0) {
left = 0;
}
if (top < 0) {
top = 0;
}
if (left + stage.stageWidth > child.width) {
left = child.width - stage.stageWidth;
}
if (top + stage.stageHeight > child.height) {
top = child.height - stage.stageHeight;
}
this.scrollRect = new Rectangle(this.left, this.top, this.width, this.height);
}
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。