Flex 带有上传的richEdiable

摘要

RichEdiable是flex的文本编辑器,可以设置文字大小,颜色,可以插入图片。

<?xml version="1.0" encoding="utf-8"?>
<s:Group 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:services="services.*"
         width="560" height="384" creationComplete="created()">
    <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.controls.Button;
            import mx.controls.Image;
            import mx.controls.Label;
            import mx.controls.LinkButton;
            import mx.controls.TextInput;
            import mx.events.CloseEvent;
            import mx.managers.PopUpManager;
               
            protected var pgs:progress= new progress();
            public var files:FileReference;
            public var filePath:LinkButton;
            public var img:Image ;
            public var text:String;
            public var htmlText:String;
            protected function created():void
            {
                   
                var upload:Button=new Button();
                img = new Image();
                img.addEventListener(MouseEvent.CLICK,deleAttach);
                filePath = new LinkButton();
                filePath.width=150;
                upload.label="上传";
                this.rc.toolbar.addChild(upload);  
                this.rc.toolbar.addChild(filePath);
                this.rc.toolbar.addChild(img); 
                files = new FileReference();
                upload.addEventListener(MouseEvent.CLICK,onClick);
                files.addEventListener(Event.SELECT, selectHandler);
                files.addEventListener(Event.CANCEL ,cancelHandler);
                   
                   
            }
               
            private function deleAttach(event:MouseEvent):void{
                var alert:Alert=Alert.show("确定要删出附件: "+files.name.toString()+ " ?","确定删除",Alert.YES|Alert.NO);
                alert.addEventListener(CloseEvent.CLOSE, delAttach);
            }
            private function delAttach(evt:CloseEvent):void{
                if(evt.detail == Alert.YES){
                    files.cancel();
                    filePath.label="";
                    img.visible = false;
                }
            }
            private function selectHandler(event:Event):void{
                   
                files.load();
                img.visible = true;
                files.addEventListener(ProgressEvent.PROGRESS,progressHandler);
                filePath.label = files.name.toString();
                img.source = "assets/ico_delete.png";
                   
                PopUpManager.addPopUp(pgs,this,true);
            }
            private function progressHandler(event:ProgressEvent):void{
                var point:Number = Math.round( event.bytesLoaded / event.bytesTotal*100);
                var s:String ="Loading:"+ point+"%";
                pgs.loadIng(s);
                pgs.pr.setProgress(point,100);
                if(point==100){
                    PopUpManager.removePopUp(pgs);
                }
                if(files.size<0)
                {
                    Alert.show("请选择上传文件","信息提示");
                    return;
                }
            }
            private function cancelHandler(event:Event):void{
                   
            }
            protected function onClick(event:MouseEvent):void
            {
                files.browse([new FileFilter("文件(*.*)","*.*")]);
            }
               
            protected function rc_changeHandler(event:Event):void
            {
                text = rc.text;
                htmlText = rc.htmlText;
            }
           
               
        ]]>
    </fx:Script>
    <mx:RichTextEditor id="rc" width="100%" height="100%" borderVisible="false"
                       change="rc_changeHandler(event)" chromeColor="#C2FDFA"
                       dropShadowVisible="false" fontFamily="SimSun"/>
</s:Group>


IT家园
IT家园

网友最新评论 (0)