AS3 包装器访问 AS1 变量

发布于 2024-07-29 13:49:07 字数 738 浏览 6 评论 0原文

好的,我有一个 Flash CS3 (+ AS3) 程序,它正在加载另一个 Flash 程序(在本例中称为“pacman_main.swf”)。 我确定这是一个相当旧的 SWF,因为它是用 Flash 5 和 AS1 制作的(耶!)。

我希望父 SWF(又名包装器)能够访问子 SWFG(又名“pacman_main.swf”)的变量,特别是分数。 这样我就可以将分数提交给第三方 PHP/mySQL 数据库等等。

function checkScore() {
    // Get the score and submit it
}

submitScore.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
    checkScore();
}

var loader:Loader = new Loader();
loader.load(new URLRequest("pacman_main.swf")); 
addChildAt(loader, 0); 

我知道分数的变量名称,使用“调试”> 构建包装器后列出变量。 分数是在游戏中获得 18 个 pac-dots 后列为“Variable _level0.instance5.instance6.score = 180”的变量。 我如何在我的“checkScore”函数中访问它?

谢谢!

Okay, so I have a Flash CS3 (+ AS3) program which is loading another flash program (called "pacman_main.swf" in this example). I've determined this is a rather old SWF, as it is made in Flash 5 and AS1 (yippee!).

I want the parent SWF (a.k.a. the wrapper) to be able to access the variables, specifically the score, of the child SWFG (a.k.a. "pacman_main.swf"). This is so I can submit the score to a 3rd party PHP/mySQL db blah blah.

function checkScore() {
    // Get the score and submit it
}

submitScore.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
    checkScore();
}

var loader:Loader = new Loader();
loader.load(new URLRequest("pacman_main.swf")); 
addChildAt(loader, 0); 

I know the variable name of the score, using the Debug > List Variables after building the wrapper. The score is a variable listed as "Variable _level0.instance5.instance6.score = 180" after getting 18 pac-dots in the game. How would I access that in my "checkScore" function?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2024-08-05 13:49:07

最新的 Flash 播放器中包含两个虚拟机,即用于 as3 的 AVM2 和用于 as2/as1 的 AVM1。 因此,当您将 as1/as2 swf 加载到闪存时,它的类型为 AVM1Movie,将由 AVM1 运行。 不幸的是,AVM2 几乎无法访问 AVM1 上运行的对象,事实上,“AVM1Movie 对象和 AVM2 对象之间不允许进行互操作(例如调用方法或使用参数)”。

您可以访问 as1 源代码吗? 如果您这样做,我建议每次分数变化时触发事件,您可以在包装类中侦听这些事件,而不必担心直接访问分数变量。

您可以此处了解有关 AVM1Movie 的更多信息

The latest flash players have two virtual machines packaged in them, the AVM2 for as3, and AVM1 for as2/as1. Because of this, when you load an as1/as2 swf into flash it is of the type AVM1Movie, which will be run by the AVM1. Unfortunately, the AVM2 has little access to the objects running on AVM1, in fact, "no interoperability (such as calling methods or using parameters) between the AVM1Movie object and AVM2 objects is allowed".

Do you have access to the as1 source code? If you do I suggest firing off events every time the score changes, you can listen for these events in your wrapper class and not have to worry about accessing the score variable directly.

You can read more about AVM1Movie here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文