Flex學習筆記(2)

來源:互聯網
上載者:User

學習中遇到轉換錯誤

TypeError: Error #1034: 強制轉換類型失敗:無法將 mx.managers::DragManagerImpl@7833851 轉換為 mx.managers.IDragManager。

轉載別人的詳細解決辦法以及出現問題的根本原因

載入卸載flex module觸發的DragManager的錯誤,在主application裡面聲明了一個moduleLoader用來載入模組,放置了兩個按鈕來控制重複載入卸載,按下第一個按鈕載入模組,按下另外一個按鈕時卸載模組,載入使用moduleLoader的load方法,卸載使用 unloadModule()方法,模組裡放置了一個list,測試過程中發現,當重新載入模組,也就是執行了一次unloadModule方法然後按第一個按鈕重新載入模組,這個時候如果去點擊list裡面任何一行都會出現如上的錯誤,解決的辦法很簡單,就是在主應用裡面加上如下兩句:
import mx.managers.DragManager;
private var dragManager:DragManager;
轉載另一個解決辦法:

這屬於Module的共用代碼問題(shared code),
當Module中使用managers時(如PopUpManager,DragManager, HistoryManager)容易出現這個問題,
manager的方法都是靜態方法,整個應用程式中建立了一個該manager介面的singleton,
但module僅在自己的Application domain中使用該singleton, 當多個module使用同一個singleton且main
application沒有使用時,就會出現這個Null 物件引用問題:首先引入某manager的module不能將該manager介面的singleton跟其

他module共用,其他module調用該Manager的方法時,應用程式不會再建立該manager介面的執行個體,這個module就無法引用到該manager介面的執行個體,就出現了Null 物件引用問題,可以參考Flex的源碼。

預設情況下,Accordion和TabNavigator的 historyManagementEnabled =
true;而ViewStack的historyManagementEnabled = false;
所以使用TabNavigator和Accordion時要注意HistoryManager的共用代碼問題。另,僅一個module使用HistoryManager時,卸載之後又載入該module也會出現該問題,說明第二次載入時相當於一個新的module了。

一個解決辦法:
在main application 中引入相關manager,可以通過在main application中申明manager的引用即可,如:
import mx.managers.HistoryManager;
var historyManager:HistoryManager;
其他manager類似。
還可以將共用代碼作為module載入到main applicaiton的application domain,具體講解可以參考Alex
Harui的ppt:
http://blogs.adobe.com/aharui/presentations/ 下面關於module的presentation, 講得很詳細

第二個是答案是類似的:

Hello following code in your main application

        import mx.Managers.*;
        private var _dragManager:DragManager;
        private var _historyManager:HistoryManager;
        private var _popupManager:PopUpManager;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.