- package code
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Loader;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.geom.Matrix;
- import flash.net.URLRequest;
- import module.TextEditview;
- import module.photEditview;
- import mx.containers.Canvas;
- import mx.controls.Image;
- import mx.controls.TextArea;
- import mx.core.Container;
- import mx.managers.PopUpManager;
- import mx.rpc.events.ResultEvent;
- import mx.rpc.http.mxml.HTTPService;
- public class ProductHandlerBasic extends Container
- {
- private var _currentStage:Container ;
- private var _productID:Number ;
- private var _recordID:Number=-1 ; ;
- private var _defaulModuleUrl:String ;
- private var _productDataContent:XML ;
- private var _productInfo:XML ;
- public var _testTextArea:TextArea ;
- private var _photoCoordinateData:XML ;
- private var _httpservice:HTTPService ;
- private var _currentphotoNum:Number =0 ; ;
- private var _currentpageNum:Number =0 ;
- private var _currentpageData:XML ;
- private var _currentcoordinateData:XMLList ;
- private var _userstage:Canvas ;
- private var _backgroundImage:Image= new Image() ;
- private var _productInnerNum:Number = 0 ;
- public function ProductHandlerBasic()
- {
- _httpservice = new HTTPService();
- _httpservice.showBusyCursor = true ;
- _httpservice.method = "post" ;
- _httpservice.url = "/HttpServiceSlt";
- _httpservice.resultFormat="xml";
- _httpservice.addEventListener(ResultEvent.RESULT,createEditProudctContent);
- _backgroundImage.addEventListener(MouseEvent.CLICK,photoClickHandler);
- _backgroundImage.addEventListener(MouseEvent.DOUBLE_CLICK,photoDoubleClickHandler);
- _backgroundImage.doubleClickEnabled = true ;
- }
- public function get previewURL():String{
- return _productInfo.product.(@id==_productID).previewURL ;
- }
- public function get price():Number{
- return _productInfo.product.(@id==_productID).price ;
- }
- public function get unit():String{
- return _productInfo.product.(@id==_productID).unit ;
- }
- public function get pages():Number{
- return _productInfo.product.(@id==_productID)..label.length();
- }
- public function get stepPrice():Number{
- return _productInfo.product.(@id==_productID)..stepprice;
- }
- public function get duplexPrice():Number{
- return Math.round((this.productInnerNum*stepPrice+price)*100)/100 ;
- }
- public function get mbClass():XMLList{
- return _productInfo.product.(@id==_productID)..subject;
- }
- public function get typename():String{
- return _productInfo.product.(@id==_productID).file ;
- }
- public function get productInnerNum():Number{
- return _productDataContent.innernumber;
- }
- public function set productInnerNum(p:Number):void{
- _productDataContent.innernumber = p;
- }
- public function get classid():String{
- return [email protected] ;
- }
- public function set currentStage(c:Container):void{
- this._currentStage = c ;
- }
- public function get currentStage():Container{
- return this._currentStage ;
- }
- public function set productID(p:Number):void{
- this._productID = p ;
- }
- public function get productID():Number{
- return this._productID ;
- }
- public function set recordID(r:Number):void{
- this._recordID= r ;
- }
- public function get recordID():Number{
- return this._recordID ;
- }
- public function set defaulModuleUrl(url:String):void{
- this._defaulModuleUrl = url ;
- }
- public function get defaulModuleUrl():String{
- return this._defaulModuleUrl ;
- }
- public function set productInfo(info:XML):void{
- this._productInfo = info ;
- }
- public function get productInfo():XML{
- return this._productInfo ;
- }
- public function set httpservice(h:HTTPService):void{
- this._httpservice = h ;
- }
- public function get httpservice():HTTPService{
- return this._httpservice ;
- }
- public function set photoCoordinateData(p:XML):void{
- this._photoCoordinateData = p ;
- }
- public function get photoCoordinateData():XML{
- return this._photoCoordinateData ;
- }
- public function set userstage(s:Canvas):void{
- this._userstage = s ;
- }
- public function get userstage():Canvas{
- return this._userstage ;
- }
- public function set currentpageNum(c:Number):void{
- this._currentpageNum = c ;
- }
- public function get currentpageNum():Number{
- return this._currentpageNum ;
- }
- public function set currentphotoNum(p:Number):void{
- this.currentphotoNum = p ;
- }
- public function get currentphotoNum():Number{
- return this._currentphotoNum ;
- }
- public function set productDataContent(p:XML):void{
- this.productDataContent = p ;
- }
- public function get productDataContent():XML{
- return this._productDataContent ;
- }
- private function photoClickHandler(e:MouseEvent):void{
- var img :Image = null ;
- for(var i:int=0;i<this._currentcoordinateData.pic.length();i++){
- img = this._userstage.getChildAt(i) as Image ;
- revertPhotoAlpha();
- if(img.hitTestPoint(mouseX,mouseY)){
- this._currentphotoNum = i ;//当前照片的号码
- img.alpha = 0.5 ;
- break ;
- }
- }
- }
- private function photoDoubleClickHandler(e:MouseEvent):void{
- var img_ :Image = null ;
- for(var i:int=0;i<this._currentcoordinateData.pic.length();i++){
- img_ = this._userstage.getChildAt(i) as Image ;
- revertPhotoAlpha();
- if(img_.hitTestPoint(mouseX,mouseY)){
- this._currentphotoNum = i ;
- this.revertPhotoAlpha() ;
- var url_:String = this._productDataContent.item[_currentpageNum]..img[i][email protected] ;
- var x_ :Number = this._productDataContent.item[_currentpageNum]..img[i][email protected] ;
- var y_ :Number = this._productDataContent.item[_currentpageNum]..img[i][email protected] ;
- var w_ :Number = this._productDataContent.item[_currentpageNum]..img[i][email protected] ;
- var h_ :Number = this._productDataContent.item[_currentpageNum]..img[i][email protected] ;
- var photoEdit_:photEditview = new photEditview();
- photoEdit_.producthandlerBase = this ;
- PopUpManager.addPopUp(photoEdit_,this._currentStage,true);
- photoEdit_.initphotoEditParams(img_,url_,x_,y_,w_,h_);
- break ;
- }
- }
- }
- private function revertPhotoAlpha():void{
- var img:Image = null ;
- for(var i:int=0;i<this._currentcoordinateData.pic.length();i++){
- img = this._userstage.getChildAt(i) as Image ;
- if(img.alpha==0.5){
- img.alpha = 1 ;
- break ;
- }
- }
- }
- public function createProductContent():void{
- if(this._recordID==-1){
- this.createNewProudctContent() ;
- return ;
- }
- //编辑产品
- var params:Object = new Object() ;
- params.methodName = "getProductContent" ;
- params.random= Math.random() ;
- params.pid= this._recordID ;
- //this._testTextArea.text = "recordid=="+this._recordID ;
- this._httpservice.send(params) ;
- }
- private function createNewProudctContent():void{
- _productDataContent = <wdxc></wdxc> ;
- var xmllist_t:XML = new XML(this._productInfo.product.(@id==_productID));
- var count:Number = xmllist_t.count ;
- for(var i:int=0;i<count;i++){
- var itemNode:XML = <item></item>;
- var photoNode:XML =<photo></photo>;
- for(var j:int=0;j<13;j++){
- photoNode.appendChild(<img url="" x="-1" y="" width="" height=""/>);
- }
- if(this._productID==598){
- itemNode.appendChild(<bs>{_defaulModuleUrl.replace(".gif","_"+(i+1)+".gif")}</bs>);
- }else{
- itemNode.appendChild(<bs>{this._defaulModuleUrl}</bs>);
- }
- itemNode.appendChild(photoNode) ;
- itemNode.appendChild(<txt><info></info></txt>);
- _productDataContent.appendChild(itemNode);
- }
- _productDataContent.appendChild(<innernumber>0</innernumber>);
- //创建是否需要邮票和信封组件
- createOtherCom();
- this.initCurrentPageInfoToStage(true);
- }
- private function createEditProudctContent(e:ResultEvent):void{
- _productDataContent = new XML(e.result);
- createOtherCom();
- this.initCurrentPageInfoToStage(false);
- }
- private var _defaultText:String = "单击此处输入文字" ;
- public function initCurrentPageInfoToStage(recompute:Boolean):void{
- this._currentphotoNum = 0 ;
- _currentpageData = new XML(this._productDataContent.item[this._currentpageNum]) ;
- this._userstage.removeAllChildren();
- for(var i:int=0;i<getCurrentPhotoCount(_currentpageNum);i++){
- var img1_t:Image = new Image() ;
- this._userstage.addChild(img1_t);
- img1_t.name="img_"+i;
- img1_t.x = _currentcoordinateData.pic[i][email protected] ;
- img1_t.y = _currentcoordinateData.pic[i][email protected] ;
- img1_t.width = _currentcoordinateData.pic[i][email protected] ;
- img1_t.height = _currentcoordinateData.pic[i][email protected] ;
- img1_t.scaleContent = true ;
- this.loadphotoToStage(img1_t,i,recompute,_productDataContent.item[_currentpageNum].photo.img[i][email protected]);
- }
- _backgroundImage.source = (this._productDataContent.item[this._currentpageNum].bs).toString();
- this._userstage.addChild(_backgroundImage);
- for(var k:int=0;k<_currentcoordinateData.txt.length();k++){
- var textInfo_:TextArea = new TextArea() ;
- textInfo_.alpha = 0 ;
- textInfo_.setStyle("fontSize","12");
- textInfo_.name = "txt_"+k ;
- textInfo_.x = _currentcoordinateData.txt[k][email protected] ;
- textInfo_.y = _currentcoordinateData.txt[k][email protected] ;
- textInfo_.width= _currentcoordinateData.txt[k][email protected] ;
- textInfo_.height = _currentcoordinateData.txt[k][email protected] ;
- textInfo_.editable = false ;
- if(_productDataContent.item[_currentpageNum].txt.info[k]==""||
- _productDataContent.item[_currentpageNum].txt.info[k]==null){
- textInfo_.text = _defaultText ;
- }else{
- textInfo_.htmlText = _productDataContent.item[_currentpageNum].txt.info[k] ;
- }
- textInfo_.addEventListener(MouseEvent.CLICK,openTextEditview) ;
- this._userstage.addChild(textInfo_);
- }
- }
- public function openTextEditview(e:MouseEvent):void{
- var textInfo_:TextArea = TextArea(e.currentTarget);
- var tev_ :TextEditview = new TextEditview() ;
- PopUpManager.addPopUp(tev_,_currentStage,true,null);
- tev_.targetLabelName = textInfo_.name ;
- tev_.phander = this ;
- var n_:Number = textInfo_.name.split("_")[1]; ;
- tev_.my_rte.htmlText =_productDataContent.item[_currentpageNum].txt.info[n_] ;
- tev_.my_rte.width = textInfo_.width ;
- tev_.my_rte.height =textInfo_.height ;
- tev_.my_rte.maxWidth = textInfo_.width ;
- tev_.my_rte.maxHeight = textInfo_.height ;
- tev_.x = 100 ;
- tev_.y = 100 ;
- }
- public function saveUserInputText(html_:String,txt_:String,labelname_:String):void{
- var lab_:TextArea = this._userstage.getChildByName(labelname_) as TextArea;
- if(txt_==null||txt_.length==0||txt_==""){
- lab_.text= _defaultText ;
- } else{
- lab_.htmlText = html_ ;
- var n_:Number = labelname_.split("_")[1]; ;
- _productDataContent.item[_currentpageNum].txt.info[n_] = html_ ;
- }
- }
- public function getCurrentPhotoCount(num_:Number):Number{
- var a1:Array = this._productDataContent.item[num_].bs.split("/");
- var picname:String = a1[a1.length-1];
- _currentcoordinateData=_photoCoordinateData.subject.mb.(@picname==picname);
- return this._currentcoordinateData.pic.length();
- }
- public function getCurrentTextCount(num_:Number):Number{
- var a1:Array = this._productDataContent.item[num_].bs.split("/");
- var picname:String = a1[a1.length-1];
- _currentcoordinateData=_photoCoordinateData.subject.mb.(@picname==picname);
- return this._currentcoordinateData.txt.length();
- }
- public function loadphotoToStage(targetimg:Image,num:Number,recompute:Boolean,targerurl:String):void{
- if(targerurl==null||targerurl==""){
- return ;
- }
- //this._testTextArea.text ="url=="+targerurl+"targerurl.length"+targerurl.length;
- var ph_t:ProductHandlerBasic = this ;
- var loader_t:Loader = new Loader();
- loader_t.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
- var width1:Number=0 ;
- var height1:Number=0;
- var x1:Number =0 ;
- var y1:Number =0 ;
- x1 = ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] ;
- y1 = ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] ;
- width1 = ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] ;
- height1 = ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] ;
- var oldbitmap_t:Bitmap = new Bitmap() ;
- var l:Loader = e.target.loader as Loader;
- var oldbitmap_tdata:BitmapData = new BitmapData (l.width,l.height) ;
- oldbitmap_tdata.draw(l);
- if(recompute||x1==-1){
- var scale_t:Number =targetimg.width/targetimg.height ;
- var h2:Number = l.width/scale_t ;
- if(h2<=l.height){
- height1 = h2 ;
- width1 = l.width ;
- }else{
- height1 = l.height ;
- width1 = height1*scale_t ;
- }
- x1 = (l.width-width1)/2 ;
- y1 = (l.height-height1)/2;
- ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] = x1 ;
- ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] = y1 ;
- ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] = width1 ;
- ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] =height1 ;
- ph_t._productDataContent.item[ph_t._currentpageNum]..img[num][email protected] = targerurl ;
- }
- var newbitmap_t:BitmapData = new BitmapData(width1,height1);
- //坐标转化,把坐标移到裁剪区域的位置,宽度和高度在cutbitmapdata里指定。
- var matrix:Matrix = new Matrix(1, 0, 0, 1, -x1, -y1);
- newbitmap_t.draw(oldbitmap_tdata, matrix);
- oldbitmap_t.bitmapData = newbitmap_t ;
- targetimg.source = oldbitmap_t ;
- targetimg.scaleContent = true ;
- ph_t._currentphotoNum++ ;
- });
- loader_t.load(new URLRequest(targerurl));
- }
- public function moduleChange(url:String):void{
- //豪华折叠卡一次换3张
- if(this.typename=="replicatecard"){
- this._productDataContent.item[0].bs = url.replace(".gif","_1.gif") ;
- this._productDataContent.item[1].bs = url.replace(".gif","_2.gif") ;
- this._productDataContent.item[2].bs = url.replace(".gif","_3.gif") ;
- } else{
- this._productDataContent.item[this._currentpageNum].bs = url ;
- }
- initCurrentPageInfoToStage(true);
- }
- public function albumPhotoClickHandler(url:String):void{
- //======当前模板的图片个数
- var t:Number = _currentcoordinateData.pic.length();
- if(this._currentphotoNum>t-1){
- this._currentphotoNum = 0 ;
- }
- var img:Image = this._userstage.getChildByName("img_"+this._currentphotoNum) as Image ;
- if(img==null){
- return ;
- }
- this.loadphotoToStage(img,this._currentphotoNum,true,url);
- }
- public function saveCurrentPageData(p1_:Number,p2_:Number,url_:String,x_:Number,y_:Number,w_:Number,h_:Number):void{
- _productDataContent.item[p1_]..img[p2_][email protected] =x_ ;
- _productDataContent.item[p1_]..img[p2_][email protected] =y_ ;
- _productDataContent.item[p1_]..img[p2_][email protected] =w_ ;
- _productDataContent.item[p1_]..img[p2_][email protected] =h_ ;
- _productDataContent.item[p1_]..img[p2_][email protected]=url_ ;
- }
- public function createOtherCom():void{
- //card.MAIN.right_id.sendAlbumInfoRequest();
- if(this.productInnerNum==1){
- card.MAIN.radbut1.selected = true ;
- }else{
- card.MAIN.radbut2.selected = true ;
- }
- card.MAIN.header_id.recomputePrice();
- card.MAIN.right_id.initAlbum();
- }
- }
- }