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;
        }
// 


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

相关文章:

  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-02-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-11-20
  • 2021-06-04
  • 2021-10-31
相关资源
相似解决方案