AS3 从外部 SWF 实例化类 [英] AS3 Instantiate Class From External SWF

查看:23
本文介绍了AS3 从外部 SWF 实例化类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和我的朋友聊天,他相信你可以做到,并说他已经做到了,但我无法让它发挥作用.

I was chatting with my buddy about this, he is convinced you can do this and says he has done it, but I cannot get this to work.

我想知道这是否可能.我尝试在外部下载的 SWF 中键入一个 var 作为类,然后创建一个实例,但无法做到.

I am wondering if it is even possible at all. I tried typing a var as a Class that is within the externally downloaded SWF and then making an instance but no can do.

一些代码

私有静态函数 onCompleteHandler(e:Event){
仪表板对象 = e.target.content;
//registerClassAlias("Dashboard", );不起作用
var dash:Class = getDefinitionByName("Dashboard") as Class;
var myDash = new dash();
跟踪(myDash.show);
}

错误

ReferenceError:错误#1065:未定义变量仪表板.
在 global/flash.utils::getDefinitionByName()
在 System$/onCompleteHandler()

因此,除非在项目 SWF 中编译,否则您似乎无法创建类的实例.如果是真的,这就是我想要它做的.我不希望人们仅仅通过下载我在这里构建的 SWF 文件来尝试创建我的类的实例.

So it seems you cannot make an instance of a class unless it is complied within the project SWF. Which if true is what I want it to do. I do not want people trying to make instances of my classes just from downloading the SWF file for what I am building here.

谢谢

推荐答案

你需要做两件事:

  1. Dashboard 一个包(package.to.Dashboard).与有包的类相比,无包类以编译形式被赋予不同的属性(受保护的命名空间),使外部 SWF 无法访问它们.
  2. 确保您加载的 SWF 加载到与父级相同的 ApplicationDomain 中
  1. Give Dashboard a package (package.to.Dashboard). Package-less classes are given different attributes (a protected namespace) in compiled form than those with packages, making them inaccessible to external SWFs.
  2. Ensure that your loaded SWF is loaded into the same ApplicationDomain as the parent

然后您应该能够使用加载的 SWF 中的 getDefinitionByNamenew 返回的 Class.

You should then be able to use getDefinitionByName from the loaded SWF and new the return Class.

这篇关于AS3 从外部 SWF 实例化类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆