怎么将.mxml改写成.as
这个是.mxml文件
<?xml version="1.0" encoding="utf-8"?><actionscript:ImageClose xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:actionscript="flex.actionscript.*" source="{sr}" width="130" height="130" mouseDown="mouseDownHandler(event)" complete="image1_completeHandler(event)"> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <fx:Script> <![CDATA[ import flex.actionscript.ImageClose; import mx.controls.Image; import mx.core.DragSource; import mx.events.DragEvent; import mx.managers.DragManager; [Bindable] private var sr:Object; //设置数据源 public function set setSource(str:Object):void{ sr=str; } protected function mouseDownHandler(event:MouseEvent):void { this.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler); this.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler); } private function mouseMoveHandler(event:MouseEvent):void{ //定义拖拽图标 var dsId:Image=new Image(); //定义拖拽挂载的数据源 var drags:DragSource= new DragSource(); //定义拖拽对象 var dsItem:Image=event.currentTarget as Image; //添加拖拽数据源 drags.addData(dsItem,"img"); drags.addData(event.currentTarget.mouseX,"X"); drags.addData(event.currentTarget.mouseY,"Y"); //定义要拖动的图像 dsId.source= event.currentTarget.source; //定义拖动显示的大小 dsId.width=178; dsId.height=121; //启动拖拽 DragManager.doDrag(dsItem,drags,event,dsId); } private function mouseUpHandler(event:MouseEvent):void{ this.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler); this.removeEventListener(MouseEvent.MOUSE_UP,mouseUpHandler); } //image自适应图片的宽和高 protected function image1_completeHandler(event:Event):void { if(this.content.width >= this.width && this.content.height >= this.height){ if((this.contentWidth / this.width) > (this.contentHeight / this.height)){ changeHeight(); } else if((this.contentWidth / this.width) < (this.contentHeight / this.height)){ changeWidth(); } } else if(this.content.width >= this.width){ changeHeight(); } else if(this.content.height >= this.height){ changeWidth(); } else if(this.content.width < this.width && this.content.height < this.height){ if((this.contentWidth / this.width) > (this.contentHeight / this.height)){ changeHeight(); } else if((this.contentWidth / this.width) < (this.contentHeight / this.height)){ changeWidth(); } } } //改变宽度 private function changeWidth():void{ this.width=(this.height/this.content.height) * this.content.width; } //改变高度 private function changeHeight():void{ this.height=(this.width/this.content.width) * this.content.height; } ]]> </fx:Script> </actionscript:ImageClose>
package flex.actionscript{ public class UploadImage extends ImageClose { public function UploadImage() { super(); } }}