2008/05/01 | MVC模式练习::::::>窗口拖动缩放效果演示
类别(flash学习) | 评论(6) | 阅读(941) | 发表于 00:46

主代码如下:

package {
/**
* @author : CYPL
* @date : 2008.4.30
*/
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;
public class DisplayObjectTransform extends Sprite {
  private var _displayisplayObject;
  private var _zoomModel:ZoomModel;
  private var _zoomControl:ZoomControl;
  private var _zoomView:ZoomView;
  public function DisplayObjectTransform(displayisplayObject,target:Stage) {
   _display=display;
   _zoomModel=new ZoomModel;
   _zoomModel.setRect(new Rectangle(_display.x,_display.y,_display.width,_display.height));
   _zoomView=new ZoomView(_zoomModel,_display);
   _zoomControl=new ZoomControl(_zoomModel,_zoomView);
   addChild(_zoomView);
   target.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
   target.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
   target.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
   target.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
   target.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);
   
   _zoomModel.addEventListener(Event.CHANGE,_zoomView.update);

  }
  private function mouseMoveHandler(evt:MouseEvent) {
   if (_zoomModel.getDragStatus()) {
    _zoomControl.dragHandler(evt);
   } else {
    _zoomControl.mouseMoveHandler(evt);
   }
  }
  private function mouseDownHandler(evt:MouseEvent) {
   _zoomControl.mouseDownHandler(evt);
  }
  private function mouseUpHandler(evt:MouseEvent) {
   _zoomControl.mouseUpHandler(evt);
  }
  private function keyDownHandler(evt:KeyboardEvent) {
   _zoomControl.keyDownHandler(evt);
  }
  private function keyUpHandler(evt:KeyboardEvent) {
   _zoomControl.keyUpHandler(evt);
  }
  
}
}


//鼠标位于图片边缘即可拖放,同时按住SHIFT键进行中心缩放~
0

评论Comments

日志分类
首页[38]
flash学习[35]
图片收藏[1]
Apollo_Flex[2]