Skip to main content

[AIR] NativeDragEvent


在 3 月 19 日於台北舉辦的 「Adobe 3.19 AIR 上市技術講座」中看到幾個外國 Adobe AIR 範例,其中有些運用到 NativeDragEvent (AIR only) 意指使用者可以"直接拖曳"外部檔案到 AIR 視窗做互動。以下是NativeDragEvent 簡單的用法:

Flash CS3 / AIR 1.0專案
Action in frame1
Stage中有個 TextField names "txt"

import flash.desktop.Clipboard;
import flash.desktop.ClipboardFormats;

stage.nativeWindow.alwaysInFront=true;

txt.addEventListener( NativeDragEvent.NATIVE_DRAG_OVER, doDragOver );

function doDragOver(e:NativeDragEvent):void {
var cd:Clipboard = e.clipboard as Clipboard;

if (cd.hasFormat( ClipboardFormats.TEXT_FORMAT ) ) {
var str:String = e.clipboard.getData( ClipboardFormats.TEXT_FORMAT ) as String;
txt.text = str;
//貼文字
} else {
var arr:Array = e.clipboard.getData( ClipboardFormats.FILE_LIST_FORMAT ) as Array;
txt.text = arr[0].nativePath;
//第一筆File路徑
}
}

Comments

  1. 這個功能真的很方便,
    但是有個問題請教,
    是否只能使用視窗來Run這個 Air App,
    不能內嵌在網頁裡面嗎?

    謝謝

    ReplyDelete

Post a Comment

Popular posts from this blog

PureMVC 我也會 [6]

Mediator ViewComponents 與 pureMVC 架構的中介 監聽並反應 View Component 發出的 Event 可以發送與接收 Notification 儘量少操作 Proxy 公開方法,多用 sendNotification... Mediator design pattern 要多認識這個 Mediator 設計模式的話,請自行看連結說明啊! 簡單來講,假使有一個 View 裡面有好幾個 MovieClip 組成,而這些 MovieClip 會互相影響對方...這個情況在 Flash 中,通常都會變成下圖: MovieClip 直接控制其他 MovieClip 搞到整個關係很複雜...換一個元件簡直是災難。 加入 Mediator 後,示意圖就會變成: 這樣,所有的 MovieClip 都透過 Mediator 來跟其他 MovieClip 溝通,當某一個 MovieClip 替換成別的元件,這時候也只需要修改 Mediator 中的引用即可,是不是變得很乾淨?如果同一組 MovieClip 有另外一個操作模式,也只需要替換掉 Mediator 即可!天下太平啊~~~ 而 PureMVC 中就是利用 Mediator class 為與前端 ViewComponent 的中介,這樣可以切開 ViewComponent 與 PureMVC framework 的關係,不管你前端介面使用 Flash or Flex 製作都跟程式核心無關。 所以 ViewComponent 製作時只需要兩個原則,一把所有的請求都以 Event 送出由 Mediator 處理,二提供公開方法, Mediator 只需要監聽 View 的 Event,將收到的資訊透過公開方法喂進 ViewComponent 即可。 如在 ViewComponent 中: public function setList( result:Object ):void{ list.dataProvider = result as ArrayCollection; } //然後在按下取得資料的按鈕 Click action 寫上: dispatchEvent( new Event( "GET_LIST" )); 新建 Mediator 的時候一樣有幾個重點方...