- package com.wdxc {
- /**
- * ...
- * @author luqinglong
- */
- public class MouseInfo {
- /*鼠标左边缘、右边缘等*/
- private var _position:uint = 100 ;
- /*鼠标状态 按下、放开*/
- private var _state :uint = 100;
- public function MouseInfo() {
- }
- public function set position(p:uint):void {
- this._position = p ;
- }
- public function get position():uint {
- return this._position ;
- }
- public function set state(s:uint):void {
- this._state = s ;
- }
- public function get state():uint {
- return _state ;
- }
- /**
- * 是否满足对左边进行拖动拉伸的条件。
- * @return boolean
- */
- public function isStartLeftDrag():Boolean {
- if (_position == Constant.LEFT && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对右边界进行拖动拉伸的条件。
- * @return boolean
- */
- public function isStartRightDrag():Boolean {
- if (_position == Constant.RIGHT && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对上边界进行拖动拉伸的条件。
- * @return boolean
- */
- public function isStartUpDrag():Boolean {
- if (_position == Constant.UP && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对下边界进行拖动拉伸的条件。
- * @return boolean
- */
- public function isStartDownDrag():Boolean {
- if (_position == Constant.DOWN && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对裁剪区域进行拖动拉伸的条件。
- * @return boolean
- */
- public function isStartMiddleDrag():Boolean {
- if (_position == Constant.MIDDLE && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对左上角拖动拉伸的条件。
- * @return boolean
- */
- public function isStratLeftUPDrag():Boolean {
- if (_position == Constant.LEFT_UP && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对左下角拖动拉伸的条件。
- * @return boolean
- */
- public function isStratLeftDownDrag():Boolean {
- if (_position == Constant.LEFT_DOWN && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对右上角拖动拉伸的条件。
- * @return boolean
- */
- public function isStratRightUPDrag():Boolean {
- if (_position == Constant.RIGHT_UP && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- /**
- * 是否满足对右下角拖动拉伸的条件。
- * @return boolean
- */
- public function isStratRightDownDrag():Boolean {
- if (_position == Constant.RIGHT_DOWN && _state == Constant.MOUSE_DOWN) {
- return true ;
- }
- return false ;
- }
- }
- }
代码一:
- package
- {
- import com.wdxc.ImageCut;
- import com.wdxc.ImageRotation;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import flash.net.URLLoader;
- import flash.net.URLRequest;
- import flash.events.* ;
- import flash.display.*;
- import flash.geom.* ;
- import flash.net.*;
- import flash.text.TextField;
- import flash.utils.ByteArray;
- import com.wdxc.util.* ;
- import fl.containers.ScrollPane;
- import flash.display.Shape;
- import fl.events.ScrollEvent;
- import flash.external.ExternalInterface;
- import flash.system.Security;
- import flash.utils.Timer;
- import flash.events.TimerEvent ;
- import com.wdxc.* ;
- /**
- * @author luqinglong
- */
- public class Main extends MovieClip
- {
- //存储加载进来的图片数据
- private var _bitmap:Bitmap ;
- //进度条
- private var _progressbar:TextField ;
- private var picname:String ;
- public var _imageCut:ImageCut = new ImageCut() ;
- //场景引用
- public static var SCENE:MovieClip ;
- public static var _handerState:int = 0 ;
- public var pelsHint:TextField = new TextField();
- public var photoid :String = "0";
- public var ir:ImageRotation ;
- /**
- * 原图和中图的压缩比例
- */
- public var picScale :Number = 2 ;
- public function Main():void {
- flash.system.Security.allowDomain("*");
- photoid = this.loaderInfo.parameters['photoid'];
- //photoid = "284186" ;
- SCENE = this;
- menu_mc.cut_btn.addEventListener(MouseEvent.MOUSE_DOWN, this._imageCut.startCutPic);
- menu_mc.rotate_btn.addEventListener(MouseEvent.MOUSE_DOWN, rotationHandler) ;
- checkAvailable();
- this.addPelsHint();
- startLoadPic();
- }
- /**
- * 加入象素提醒
- */
- private function addPelsHint():void {
- this.addChild(pelsHint);
- //pelsHint.text = "象素不够" ;
- pelsHint.x = 150 ;
- pelsHint.y = 0 ;
- pelsHint.height = 20 ;
- this.pelsHint.width = 350 ;
- pelsHint.textColor =0xFF0000;
- }
- public function setPelsHint(p:Number,hint:String):void {
- this.pelsHint.text = "像素:" + String(p) + " " + hint ;
- }
- private function rotationHandler(e:MouseEvent):void {
- ir = new ImageRotation() ;
- ir.x = menu_mc.x ;
- ir.y = menu_mc.y ;
- this.stage.addChild(ir);
- }
- /**
- * 得到最低象素值 。
- */
- /*
- public function getMaxPels():Number {
- return this.plength/ 500 ;
- } */
- //public function setPelsScale(p:Number) {
- //this.plength = p / 500 ;
- //}
- public function set bitmap(bp:Bitmap):void {
- this._bitmap = bp ;
- }
- public function get bitmap():Bitmap {
- return this._bitmap ;
- }
- public function startLoadPic():void {
- var param:URLVariables = new URLVariables() ;
- var url:String = "/photo/LoaderPhotoServlet";
- //var url:String = "http://localhost:8080//photo/LoaderPhotoServlet" ;
- param.random = Math.floor(Math.random() * 1000);
- param.photoid = photoid ;
- //output.text = photoid ;
- //url += Math.floor(Math.random() * 1000);
- var request:URLRequest = new URLRequest(url);
- request.data = param ;
- var loader :Loader = new Loader();
- loader.load(request);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, picLoadCompleteHandler);
- }
- /**
- * 导入二进制完成
- * @param e
- */
- private function picLoadCompleteHandler(e:Event):void {
- /**删除进度条*/
- if (Main._handerState == 1||Main._handerState==2) {
- this.delVagueBg();
- delLoadingBar();
- calljs();
- }
- Main._handerState = 0 ;
- /*
- if (this._bitmap.bitmapData != null) {
- this._bitmap.bitmapData.dispose() ;
- //this.removeChild(_bitmap);
- } */
- this._bitmap = new Bitmap() ;
- var loader:Loader = e.target.loader as Loader;
- var _bitmapdata:BitmapData = new BitmapData(loader.width, loader.height);
- _bitmapdata.draw(loader);
- /**
- * 判断横版照片,竖版照片
- */
- /*
- if ( loader.height > loader.width) {
- //竖版照片
- this.cutscaleFlag = Constant.VERTICAL ;
- } */
- this._bitmap.bitmapData = _bitmapdata;
- this.addChild(_bitmap);
- this.reset() ;
- //设置原图引用
- this._imageCut.bitmap = this._bitmap ;
- this.addChild(this._imageCut);
- e.currentTarget.removeEventListener(Event.COMPLETE, picLoadCompleteHandler);
- }
- /**
- * 删除以前的Bitmapt对象,注入新的进去 。
- */
- public function removeBitmap():void {
- this.removeChild(_bitmap);
- }
- public function reset():void {
- this._bitmap.x = (Constant.LEFT_AREA_WIDTH-_bitmap.width)/2 ;
- this._bitmap.y = (Constant.SCRENE_HEIGHT - _bitmap.height) / 2 ;
- }
- public function checkAvailable():void {
- if (ExternalInterface.available){
- try {
- ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
- if (checkJavaScriptReady()) {
- //trace("JavaScript is ready.\n");
- } else {
- //trace("JavaScript is not ready, creating timer.\n");
- var readyTimer:Timer = new Timer(100, 0);
- readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
- readyTimer.start();
- }
- }catch (error:SecurityError) {
- //trace("A SecurityError occurred: " + error.message + "\n");
- //output.text = "error1";
- }catch (error:Error) {
- //trace("An Error occurred: " + error.message + "\n");
- }
- }else{
- //trace("External interface is not available for this container.");
- }
- }
- private function timerHandler(event:TimerEvent):void {
- var isReady:Boolean = checkJavaScriptReady();
- //output.appendText("123");
- if (isReady) {
- //trace("JavaScript is ready.\n");
- Timer(event.target).stop();
- }
- }
- private function receivedFromJavaScript(pid:String, plength:Number):void {
- //pelsHint.text = pid + "==" + plength ;
- this.photoid = pid ;
- //设置中图和原图的像素比
- this.picScale = plength/500 ;
- //this._bitmap.bitmapData.dispose();
- //output.text = value ;
- removeBitmap();
- // 点击了裁剪按钮时
- if (Main._handerState == 5) {
- _imageCut.removeCutMenu();
- }
- // 裁剪时候单击保存时候
- else if (Main._handerState == 6) {
- _imageCut.removeCutMenu();
- _imageCut.removeHint();
- } else if (Main._handerState == 10) {
- ir.remove();
- }
- //this._bitmap = null ;
- startLoadPic();
- }
- private function checkJavaScriptReady():Boolean {
- var isReady:Boolean = ExternalInterface.call("isReady");
- return isReady;
- }
- public function calljs():void {
- if (ExternalInterface.available) {
- ExternalInterface.call("rationAndCropComplete", "123");