小小菜鸟的web菜园子

专注FLEX,AIR,FLASH

统计

留言簿(8)

积分与排名

AMF

FLASH

FLEX

FMS

Friends

开源框架

设计之美

数据库相关

我的作品

阅读排行榜

评论排行榜

拖拽桌面的图片文件到AIR程序.

复制到AIR工程,运行:
代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout
="vertical"
    creationComplete
="init()">
    
<mx:Script>
        
<![CDATA[
            import flash.desktop.DragActions;
            import mx.controls.Alert;
            import mx.controls.Image;
            import flash.filesystem.File;
            import flash.desktop.TransferableData;
            import flash.desktop.TransferableFormats;
            import flash.events.NativeDragEvent;
            import flash.desktop.DragManager;
         
            private function init():void{
                this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER,onDragIn);
                            this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP,onDrop);
                            this.addEventListener(NativeDragEvent.NATIVE_DRAG_EXIT,onDragExit);
            }
            
        public function onDragIn(event:NativeDragEvent):void{
                   DragManager.acceptDragDrop(this);
            }

            public function onDrop(event:NativeDragEvent):void{
                DragManager.dropAction = DragActions.COPY;
                var dropfiles:Array = event.transferable.dataForFormat(TransferableFormats.FILE_LIST_FORMAT) as Array;
                for each (var file:File in dropfiles){
                    switch (file.extension){   
                        case "png" : 
                            addImage(file.nativePath);
                            break;
                        case "jpg" : 
                            addImage(file.nativePath);
                            break;
                        case "gif" : 
                            addImage(file.nativePath);
                            break;
                        default: 
                           Alert.show("Unmapped Extension");
                    }
              }
            }
           
            public function onDragExit(event:NativeDragEvent):void{
                trace("Drag exit event.");
            }
            
            private function addImage(nativePath:String):void{
                var i:Image = new Image();
            if(Capabilities.os.search("Mac") >= 0){
                            i.source = "file://" + nativePath;
                        } else {
                    i.source = nativePath;
                        }
            this.addChild(i);
            }
       
        
]]>
    
</mx:Script>
</mx:WindowedApplication>

posted on 2008-04-27 20:24 『小小菜鸟』 阅读(81) 评论(2)  编辑 收藏 所属分类: FLEX/AIR

评论

#1楼  2008-06-16 12:14 wolf2999 [未注册用户]

DragManager.dropAction = DragActions.COPY;

放到flex 里面编译,,怎么提示这句出错..   回复  引用    

#2楼  2008-06-22 08:16 marshane [未注册用户]

--引用--------------------------------------------------
wolf2999: DragManager.dropAction = DragActions.COPY;

放到flex 里面编译,,怎么提示这句出错..
--------------------------------------------------------

是的 说DragManager没定义??   回复  引用    


标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: