as3 跨域加载swf资源,并使用其中的代码

as3的安全沙箱很严格,跨域加载swf资源或使用资源中的代码的时候会出现若干问题,例如通过原件的库链接名"role"创建对应的实例的时候会出现"role"未定义的错误

 

不管放置swf资源的的server上有没有crossdomain.xml文件, 只要这个swf资源有类似 Security.allowDomain("*"); 的权限, 那么别的域的swf就能得到相应的资源

 

如果你用Loader加载as3 swf 资源的时候应该用这样的方式写 load:

 //

public  function load(url:String): void {
            
            urlStr 
=  url;
            
            var tempReq:URLRequest 
=   new  URLRequest(url);
            
if (loader  !=   null ){
                removeListeners( loader );
            }
            loader 
=   new  Loader();
            configureListeners(loader.contentLoaderInfo);
            
            var context:LoaderContext 
=   new  LoaderContext();
               context.applicationDomain 
=  ApplicationDomain.currentDomain;
            
            
try {
                loader.load(tempReq,context);                
            }
catch (e:Error){
                trace(
" error::PicLoader :  " + e);
            }
            tempReq 
=   null ;
        }
//

 通过 库链接名得到对应的Class的时候要使用如下方式:

 //

public  function getClassByName(className:String):Class {            
            
try  {
                
return  loader.contentLoaderInfo.applicationDomain.getDefinition(className)   as   Class;
            } 
catch  (e:Error) {
                
throw   new  IllegalOperationError(className  +   "  definition not found in  " + urlStr);
            }
            
return   null ;
        }
// 


这样处理的话就顺利的使用跨域资源了。 

转载于:https://www.cnblogs.com/vilyLei/articles/2039138.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值