首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

如何将.mxml改写成.as

2012-04-09 
怎么将.mxml改写成.as这个是.mxml文件JScript code?xml version1.0 encodingutf-8?actionscript:

怎么将.mxml改写成.as
这个是.mxml文件

JScript code
<?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> 



这个是.as文件
JScript code
package flex.actionscript{    public class UploadImage extends ImageClose    {        public function UploadImage()        {            super();        }    }}



要怎么改写代码啊。。。。mxml中的complete事件在as中要怎么改写代码?


[解决办法]
同意楼上的意见
你可以把他写在
构造方法里面啊
其他的代码直接粘贴进去不就可以了啊
[解决办法]
FlexEvent.CREATION_COMPLETE,
你把鼠标放在complete,会显示该事件使用的描述和事件类型。

还有在flex工程上右键选属性-->flex编译器,在附加的编译器参数输入框中,增加 -keep -generated -actionscript,会将所有的mxml文件转成as,但是转成的as写法是很变态的,你需要改下格式。
[解决办法]
建议LZ多了解下Flex组件的生命周期,非常重要。google 下很多。这个问题小case。

热点排行