flex 开发的照片书二
来源:互联网 发布:魔兽大脚 mac 编辑:程序博客网 时间:2024/05/09 14:25
- import code.*;
-
- import common.PhotoEdit;
- import common.TextEdit;
-
- import data.*;
-
- import flash.display.*;
- import flash.events.MouseEvent;
- import flash.net.URLRequest;
-
- import mx.containers.Canvas;
- import mx.controls.Image;
- import mx.controls.Label;
- import mx.core.Container;
- import mx.core.ScrollPolicy;
- public var currentPhoto:Number = 0 ;
-
- public var currentPageNum:int = 0 ;
-
- public var albumdata:XML ;
- public var cmb:String ;
-
- public var sourceurl:XML ;
-
- public var currentText:XML ;
-
-
- public var currentLabel:Label ;
-
- public static var MAIN:photobook68 ;
-
- public var c:Container ;
-
-
- public var currentBj:Image = new Image() ;
-
- private var _state:Number= 0 ;
-
- public var pid:String ;
- public var subject:Canvas ;
- public var xmlList:XMLList ;
-
- private var labelTip:String ="单击此处,输入文字";
-
- private var objImgs:Object = new Object () ;
-
- public var _stylename:String ;
-
- public var _productName:String;
-
- public var productid : Number
-
-
- public var price:Number ;
- public var pagePrice:Number ;
-
- public var typeFlag:int = 0 ;
-
-
- public var userID:Number ;
-
- internal function initUI():void{
- MAIN = this ;
-
- this.initParams();
-
- this.initXMLData() ;
-
-
- this.sendAlbumInfo() ;
-
- this.initXML(pid);
-
- this.initListener() ;
- }
-
-
-
- private function sendAlbumInfo():void{
-
- var obj:Object = new Object() ;
- obj.random = Math.random() ;
- obj.handlertype = 1 ;
- obj.userID = this.userID ;
- this.photoselectID.albumNameListId.send(obj);
- }
-
-
-
- private function initListener():void{
- this.currentBj.addEventListener(MouseEvent.CLICK,photoClickHandler);
- this.currentBj.addEventListener(MouseEvent.DOUBLE_CLICK,doubleClickPhotoHandler);
- this.currentBj.doubleClickEnabled = true ;
- }
-
-
- public function initXML(pid:String):void{
-
- if(pid==null||pid=="null"||pid==""){
- createDefaultXML() ;
- }else{
- var params:Object = new Object() ;
- params.handlertype = 7 ;
- params.productrecordid = pid ;
- productInfoId.send(params);
- }
- }
-
-
- public function loaderCurrentPageInfo(b:Boolean):void{
-
- this.currentPhoto = 0 ;
- cmb = this.albumdata.item.bs[this.currentPageNum];
- sourceurl = this.albumdata.item.photo[this.currentPageNum];
- this.currentText = this.albumdata.item.txt[this.currentPageNum];
-
-
- this.console.removeAllChildren();
-
- var a1:Array = cmb.split("/");
-
-
- var subject:String = a1[a1.length-3];
-
- var picname:String = a1[a1.length-1];
-
-
-
- xmlList = this.getXMLData(subject,picname,this.currentPageNum) ;
-
- this.subject = new Canvas() ;
- this.subject.verticalScrollPolicy = ScrollPolicy.OFF ;
- this.subject.horizontalScrollPolicy = ScrollPolicy.OFF ;
-
-
-
-
-
- this.console.addChild(this.subject) ;
-
- initMoBan();
-
-
- for(var i:int=0;i<xmlList.pic.length();i++){
-
- var c1:Canvas = new Canvas() ;
- c1.verticalScrollPolicy = ScrollPolicy.OFF ;
- c1.horizontalScrollPolicy = ScrollPolicy.OFF ;
- c1.x = xmlList.pic[i].@x ;
- c1.y = xmlList.pic[i].@y ;
- c1.width= xmlList.pic[i].@width ;
- c1.height = xmlList.pic[i].@height ;
-
- this.subject.addChild(c1);
- var _img1:Image = new Image() ;
-
- _img1.id = "img"+i;
- _img1.name = "img"+i;
- _img1.width = c1.width ;
- _img1.height = c1.height ;
- _img1.scaleContent = true ;
- this.objImgs["img"+i] = _img1 ;
- if(b==true){
- this.reLoaderPhotoByChangeBs(_img1,i);
- }else{
- this.loadPhoto(_img1,i);
- }
-
- c1.addChild(_img1) ;
- }
-
-
- initTextInfo();
-
-
- this.pagefalgcomId.changeFontStyle();
-
-
- this.changembID.changeTab(this.currentPageNum);
-
-
- this.pagefalgcomId.changeScrollPostition();
- }
-
-
- private function initMoBan():void{
-
-
- this.currentBj.source =cmb ;
-
- this.console.addChild(this.currentBj);
-
- }
-
- private function photoClickHandler(e:MouseEvent):void{
- var img :Image = null ;
- for(var i:int=0;i<this.xmlList.pic.length();i++){
- img = this.objImgs["img"+i];
- if(img.source==""){
- continue ;
- }
- var b:Boolean =img.hitTestPoint(mouseX,mouseY);
- if(b==true){
-
-
- this.alphaHandler() ;
-
-
- this.currentPhoto = i ;
- img.alpha = 0.5 ;
- break ;
- }
- }
-
- }
-
-
- public function changeFM(fm:String):void{
-
- this.currentPageNum = 0 ;
- this.albumdata.item.bs[this.currentPageNum] = fm ;
- this.currentPhoto = 0 ;
-
- this.loaderCurrentPageInfo(true);
-
- }
-
-
- public function changeCurrentBs(bs:String):void{
-
-
- this.albumdata.item.bs[this.currentPageNum] = bs ;
- this.currentPhoto = 0 ;
-
- this.loaderCurrentPageInfo(true);
- }
-
-
-
-
-
- public function loadProductInfo():void{
- albumdata = new XML(productInfoId.lastResult);
-
-
-
-
-
-
- this.loaderCurrentPageInfo(false);
-
- photobook68.MAIN.pagefalgcomId.initUI() ;
- this.initPrice() ;
- }
-
-
-
- public function choosePhotoHandler(e:MouseEvent):void{
- var i:Image = Image(e.currentTarget) ;
- var m :String = i.source.toString() ;
- m = m.replace("_2","_1") ;
-
-
- var t:Number = xmlList.pic.length();
-
-
- if(this.currentPhoto>t-1){
- this.currentPhoto = 0 ;
- }
-
-
- this.alphaHandler();
-
- var img:Image = Image(this.objImgs["img"+this.currentPhoto]);
- changePhoto(img,m,this.currentPhoto) ;
- }
-
-
-
- public function loadPhoto(img:Image,num:Number):void{
- var w1:Number, h1:Number, x1:Number,y1:Number,purl:String ;
- x1 = this.sourceurl.img[num].@x ;
- y1 = this.sourceurl.img[num].@y ;
- w1 = this.sourceurl.img[num].@width ;
- h1 = this.sourceurl.img[num].@height ;
- purl = this.sourceurl.img[num].@url ;
-
- if(purl==null||purl==""){
- return ;
- }
-
-
- if(x1==-1){
- this.reLoaderPhotoByChangeBs(img,num) ;
- return ;
- }
- var _loader:Loader = new Loader();
-
- _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
- var _bitmap:Bitmap = new Bitmap() ;
- var l:Loader = e.target.loader as Loader;
-
- var _bitmapdata:BitmapData = new BitmapData (l.width,l.height) ;
- _bitmapdata.draw(l);
- var temp:BitmapData = new BitmapData(w1,h1);
-
- var matrix:Matrix = new Matrix(1, 0, 0, 1, -x1, -y1);
- temp.draw(_bitmapdata, matrix);
-
- _bitmap.bitmapData = temp ;
- img.source = _bitmap ;
- img.scaleContent = true ;
- photobook68.MAIN.currentPhoto++ ;
- });
- _loader.load(new URLRequest(purl));
- }
-
- private function reLoaderPhotoByChangeBs(_img:Image,num:Number):void{
- var photourl:String = sourceurl.img[num].@url ;
- if(photourl==null||photourl==""){
- return ;
- }
- var w1:Number, h1:Number, x1:Number,y1:Number ;
- var p:photobook68 = this ;
- var _loader:Loader = new Loader();
- _loader.load(new URLRequest(photourl));
-
- _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
- var _bitmap:Bitmap = new Bitmap() ;
- var l:Loader = e.target.loader as Loader;
-
- var _bitmapdata:BitmapData = new BitmapData (l.width,l.height) ;
- _bitmapdata.draw(l);
-
- var s:Number =_img.width/_img.height ;
- var h2:Number = l.width/s ;
- if(h2<=l.height){
- h1 = h2 ;
- w1 = l.width ;
- }else{
- h1 = l.height ;
- w1 = h1*s ;
- }
-
- x1 = (l.width-w1)/2 ;
- y1 = (l.height-h1)/2;
-
-
- var temp:BitmapData = new BitmapData(w1,h1);
-
- var matrix:Matrix = new Matrix(1, 0, 0, 1, -x1, -y1);
- temp.draw(_bitmapdata, matrix);
- _bitmap.bitmapData = temp ;
-
- _img.source = _bitmap ;
- p.sourceurl.img[num].@x = x1 ;
- p.sourceurl.img[num].@y = y1 ;
- p.sourceurl.img[num].@width = w1 ;
- p.sourceurl.img[num].@height =h1 ;
- p.sourceurl.img[num].@url = photourl ;
- photobook68.MAIN.currentPhoto++ ;
- });
- }
-
- private function changePhoto(_img:Image,photourl:String,num:Number):void{
-
-
-
- var w1:Number, h1:Number, x1:Number,y1:Number ;
- var p:photobook68 = this ;
- var _loader:Loader = new Loader();
- _loader.load(new URLRequest(photourl));
-
- _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
- var _bitmap:Bitmap = new Bitmap() ;
- var l:Loader = e.target.loader as Loader;
-
- var _bitmapdata:BitmapData = new BitmapData (l.width,l.height) ;
- _bitmapdata.draw(l);
- var s:Number =_img.width /_img.height ;
-
- var h2:Number = l.width/s ;
- if(h2<=l.height){
- h1 = h2 ;
- w1 = l.width ;
- }else{
- h1 = l.height ;
- w1 = h1*s ;
- }
-
- x1 = (l.width-w1)/2 ;
- y1 = (l.height-h1)/2;
- var temp:BitmapData = new BitmapData(w1,h1);
-
- var matrix:Matrix = new Matrix(1, 0, 0, 1, -x1, -y1);
- temp.draw(_bitmapdata, matrix);
- _bitmap.bitmapData = temp ;
- _img.source = _bitmap ;
- _img.scaleContent = true ;
- p.sourceurl.img[num].@x = x1 ;
- p.sourceurl.img[num].@y = y1 ;
- p.sourceurl.img[num].@width = w1 ;
- p.sourceurl.img[num].@height =h1 ;
- p.sourceurl.img[num].@url = photourl ;
-
- photobook68.MAIN.currentPhoto++ ;
- });
- }
-
-
-
- private function initTextInfo():void{
- for(var i:int=0;i<xmlList.txt.length();i++){
- var lable:Label = new Label() ;
- lable.setStyle("fontSize","12");
-
- lable.id = "txt"+i ;
- lable.x = xmlList.txt[i].@x ;
- lable.y = xmlList.txt[i].@y ;
- lable.width= xmlList.txt[i].@width ;
- lable.height = xmlList.txt[i].@height ;
-
- if(this.currentText.info[i]==""||this.currentText.info[i]==null){
- lable.text = this.labelTip;
- }else{
- lable.htmlText = this.currentText.info[i] ;
- }
- lable.addEventListener(MouseEvent.CLICK,openRichText) ;
- this.console.addChild(lable);
- }
- }
-
-
- public function saveTextInfo(t:String,t2:String):void{
- this.currentLabel.htmlText = t ;
- var tname:String = this.currentLabel.id ;
- tname = tname.charAt(3) ;
- if(t2==null||t2.length==0||t2==""){
- this.currentLabel.text= this.labelTip;
- }
- this.currentText.info[Number(tname)] = this.currentLabel.htmlText;
- }
-
-
- public function openRichText(e:MouseEvent):void{
- var label:Label = Label(e.currentTarget);
- var rte :TextEdit = new TextEdit() ;
- rte.x = 100 ;
- rte.y = 100 ;
- this.currentLabel = label ;
- c = new Container() ;
- c.graphics.beginFill(0x000000);
- c.graphics.drawRect(this.x,this.y,this.width,this.height) ;
- c.graphics.endFill();
- c.alpha = 0.3 ;
- this.addChild(c);
- this.addChild(rte) ;
-
- if(label.text== this.labelTip){
- rte.my_rte.htmlText ="" ;
- }else{
- rte.my_rte.htmlText = label.htmlText ;
- }
-
- }
-
-
- public function editPhotoHandler(_img:Image,url:String,_x:Number,_y:Number,_w:Number,_h:Number):void{
-
- this.addAlphaBackgroud();
- var photoEdit:PhotoEdit = new PhotoEdit();
- this.addChild(photoEdit);
-
- photoEdit.x = (this.width - photoEdit.width)/2 ;
- photoEdit.y = (this.height - photoEdit.height)/2 ;
-
- photoEdit.setParams(_img,_x,_y,_w,_h) ;
- photoEdit.img.source = url ;
- }
-
-
-
- public function addAlphaBackgroud():void{
- c = new Container() ;
- c.graphics.beginFill(0x000000);
- c.graphics.drawRect(this.x,this.y,this.width,this.height) ;
- c.graphics.endFill();
- c.alpha = 0.3 ;
- this.addChild(c);
- }
-
-
- public function deleteAlphaBackground():void{
-
- this.removeChild(c);
- }
-
-
-
- public function doubleClickPhotoHandler(e:MouseEvent):void{
-
-
-
-
- var img :Image = null ;
- for(var i:int=0;i<this.xmlList.pic.length();i++){
- img = this.objImgs["img"+i];
- if(img.source==""){
- continue ;
- }
- var b:Boolean =img.hitTestPoint(mouseX,mouseY);
- if(b==true){
-
-
- this.alphaHandler() ;
-
-
- this.currentPhoto = i ;
-
-
- var url:String = photobook68.MAIN.sourceurl.img[this.currentPhoto].@url ;
- var x:Number = photobook68.MAIN.sourceurl.img[this.currentPhoto].@x ;
- var y:Number = photobook68.MAIN.sourceurl.img[this.currentPhoto].@y ;
- var width:Number = photobook68.MAIN.sourceurl.img[this.currentPhoto].@width ;
- var height:Number = photobook68.MAIN.sourceurl.img[this.currentPhoto].@height ;
-
- photobook68.MAIN.editPhotoHandler(img,url,x,y,width,height);
-
- break ;
- }
- }
- }
-
-
- public function getCurrentPhotoNum(i:Number):Number{
- var cmb:String = photobook68.MAIN.albumdata.item.bs[i] ;
- var a1:Array = cmb.split("/");
- var subject:String = a1[a1.length-3];
-
- var picname:String = a1[a1.length-1];
-
-
- return this.getXMLData(subject,picname,i).pic.length();
- }
-
-
-
-
- private function alphaHandler():void{
- var img:Image = null ;
- for(var i:int=0;i<this.xmlList.pic.length();i++){
- img = (this.objImgs["img"+i]);
- if(img==null||img.source==null){
- continue ;
- }
- if(img.alpha==0.5){
- img.alpha = 1 ;
- break ;
- }
-
- }
- }
- include "XmlDataHandler.as" ;