安全沙箱沖突:Loader.content:XX 不能訪問 XX 可以通過調用 Security.allowDomain 來避免此沖突。


參考資料:http://tieba.baidu.com/p/882855105

感謝:Z0287yyy

 

感謝分享精神。

 

具體解決方案:
在loader去load的時候,帶上這個參數

var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain();     // 這個是關鍵
context.checkPolicyFile =  true;
context.securityDomain = SecurityDomain.currentDomain;

Loader.load(new URLRequest(url), context);

 

原文如下:


 

如題,最近遇到這么一個難題:
SecurityError: Error #2121: 安全沙箱沖突:LoaderInfo.content:XXX1不能訪問XXX2.
可以通過調用 Security.allowDomain 來避免此沖突。

 

 

這個問題,其實很搞笑,因為跟Security.allowDomain沒有任何關系。
(也可能有,請高手留言斧正。)

因為我在主文件XXX1和子文件XXX2里面有寫了
Security.allowDomain("*");
Security.allowInsecureDomain("*");
而且crossdomain.xml文件都在。

 

 

具體解決方案:
在loader去load的時候,帶上這個參數

var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain();    //這個是關鍵
context.checkPolicyFile = true;
context.securityDomain = SecurityDomain.currentDomain;

Loader.load(new URLRequest(url), context);

 

context.applicationDomain = new ApplicationDomain();
的時候會指定新的域,與原有的flex程序域不同,所以不會出問題了。


ApplicationDomain 的說明:


加載到子域(模塊)
類似於“繼承”,子域可以直接獲得父域所有的類定義,反之父域得不到子域的。和繼承關系不同的是,如果子域中有和父域同名的類,子域定義會被忽略而使用父域的定義。

加載到同域(運行時共享庫)

類似集合里的合並關系。被加載swf里的所有類定義被合並到當前域中可以直接使用。和加載到子域相同,和當前域同名的定義也會被忽略。

加載到新域(獨立運行的程序或模塊)
swf載入指定域之前,先要檢查該域及其父域中是否存在同名類,重復定義一概忽略。如果加載別人寫的程序,或者使用舊版本的主程序加載新版本的模塊,為避免類名沖突就要加載到新域獨立運行以使用自己的類。

 
當然flash加載flex,或者flex加載flash就沒有這個問題。
因為flash和flex的空間可能就不同。

只有flex加載flex會出現這個問題。。稀爛。。。

另外,
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
也是不行的。。。他意味着加載到同一個有域,,有沖突,(程序可能會卡在這個地方)

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM