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

查看:194
本文介绍了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中,然后做一个实例,但没有做不到的。

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.

一些code

私有静态函数onCompleteHandler(五:事件) {
    dashboardObject = e.target.content;
        // registerClassAlias​​(仪表盘,);不工作
    VAR破折号:类= getDefinitionByName(仪表板)作为等级;
    VAR myDash =新的破折号();
    跟踪(myDash.show);
}

private static function onCompleteHandler(e:Event) {
dashboardObject = e.target.content;
// registerClassAlias("Dashboard", ); doesnt work
var dash:Class = getDefinitionByName("Dashboard") as Class;
var myDash = new dash();
trace(myDash.show);
}

错误

的ReferenceError:错误#1065:变量仪表盘没有定义
。     全球/ flash.utils :: getDefinitionByName()
    在系统$ / onCompleteHandler()

ReferenceError: Error #1065: Variable Dashboard is not defined.
at global/flash.utils::getDefinitionByName()
at 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. 控制台包( package.to.Dashboard )。包无类给出比那些包编译的形式不同的属性(受保护的命名空间),使他们无法进入外部主权财富基金。
  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

您应该然后就可以使用 getDefinitionByName 从加载的SWF和返回

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

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

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