热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用Flash+AS3发布/调试配置-Release/DebugConfigurationswithFlash+AS3

IrecentlyranintoanembarrassingsituationwithsomeFlashcodingwhereIhadtoaccidentallysen

I recently ran into an embarrassing situation with some Flash coding where I had to accidentally sent clients a build where not all my debugging flags and variables were unset. (It was sending requests to the debug instead of release server, etc...)

我最近遇到了一些令人尴尬的情况,我不得不意外地向客户端发送了一个构建,而不是所有的调试标志和变量都未设置。 (它是向调试发送请求而不是发布服务器等...)

Part of this was poor code organization on my part; I've resolved that.

部分原因是我的代码组织很差;我已经解决了这个问题。

However, Flash doesn't seem to allow one to set different build configurations, and the Actionscript Compile settings hosts a variety of switches arranged in such a fashion that forgetting to check/uncheck something (OMG, I forgot to disable debugger support!) might just happen, as it did with me. In any case, I find that manually jumping between my release config and debug config to be easy to screw up.

但是,Flash似乎不允许设置不同的构建配置,并且Actionscript Compile设置托管各种交换机,这些交换机以忘记检查/取消选中某些内容的方式排列(OMG,我忘了禁用调试器支持!)就像发生在我身上一样。在任何情况下,我发现在我的发布配置和调试配置之间手动跳转很容易搞砸。

So, other developers, what techniques do you use to error-proof jumping between your testing config, and the build config that you issue to your boss/clients/whoever?

那么,其他开发人员,您使用什么技术来防止在测试配置和您向老板/客户/谁发出的构建配置之间跳转?

I know I should probably slow down but I would much prefer setting up something to where I could just flip a switch. I'm just jumping back into Flash after a long hiatus (Flash MX + a bit of 2004).

我知道我应该放慢速度,但我更喜欢把东西放到我可以翻转开关的地方。经过长时间的中断后我才重新回到Flash中(Flash MX + 2004年的一点点)。

Oh, and I'm aware of the futility of disabling debug support and setting import passwords and all that, my goal is to simply keep the script kiddies out of my project. Decompilers trump all that so.....

哦,我知道禁用调试支持和设置导入密码是徒劳的,所有这一切,我的目标是简单地将脚本小子放在我的项目之外。反编译器胜过一切......

Anyways, Thanks!

4 个解决方案

#1


I use an environment class, like this:

我使用环境类,如下所示:

public class MyEnvironment {
  public static const DEBUG:Boolean = true;
  public static const SERVER:String = 'localhost';
  // More here
}

Import this into your main ActionScript class, and make sure all of your helper functions reference it. For instance, your debugger functions should only run if MyEnvironment.DEBUG is true, and your network functions should send requests to MyEnvironment.SERVER.

将其导入到主ActionScript类中,并确保所有辅助函数都引用它。例如,只有在MyEnvironment.DEBUG为true时才运行调试器函数,并且您的网络函数应该向MyEnvironment.SERVER发送请求。

In my setup, I'd save this as MyEnvironment.as. (Obviously, the class name would be different in real life.) I'd also save copies as MyEnvironment.as-debug and MyEnvironment.as-release; the latter would have different settings. Then, if I need a release build, my build script would copy MyEnvironment.as-release to MyEnvironment.as (overwriting the original), and recompile. That'll load all of my release settings into my main ActionScript class; opposite if I run the script for a debug build.

在我的设置中,我将其保存为MyEnvironment.as。 (显然,类名在现实生活中会有所不同。)我还将副本保存为MyEnvironment.as-debug和MyEnvironment.as-release;后者会有不同的设置。然后,如果我需要发布版本,我的构建脚本会将MyEnvironment.as-release复制到MyEnvironment.as(覆盖原始版本),然后重新编译。这会将我的所有发布设置加载到我的主ActionScript类中;如果我为调试版本运行脚本,则相反。

#2


If you're using Flash CS4 you can use config constants. You'll find them under Publish Settings|ActionScript3.0 Settings...|Config Constants

如果您使用的是Flash CS4,则可以使用配置常量。您可以在“发布设置”|“ActionScript3.0设置...”|“配置常量”下找到它们

If you added DEBUG::PLAYER then you can use code like this:

如果您添加了DEBUG :: PLAYER,那么您可以使用以下代码:

config namespace DEBUG;

//... code here ...

DEBUG::PLAYER
{
    trace("Player state here");
}

Now you can just switch the constant between true and false.

现在你可以在true和false之间切换常量。

#3


A good idea is to use a visual hint when your in debugging mode. When the DEBUG flag is set, display a TextField with 'debug mode' and maybe version number, or something like that, in one of the corners of the screen.

一个好主意是在调试模式下使用视觉提示。设置DEBUG标志后,在屏幕的一个角落中显示带有“调试模式”的TextField,可能还有版本号或类似内容。

When your doing your final tests before sending it to a client, you will see you've forget to disable DEBUG mode.

当您在将其发送给客户端之前进行最终测试时,您将看到您忘记禁用DEBUG模式。

It surely depends on how you structure your project. As described in another answer, it's good to store the flag in a high level 'global' class accessible through the whole application.

这当然取决于你如何构建你的项目。如另一个答案中所述,将标志存储在可通过整个应用程序访问的高级“全局”类中是很好的。

#4


I use a flashvar called "TestingEnvironment". On application start, I check in loaderInfo.parameters to see if it's set to 'true' (a string literal, not a boolean), and if it is, I set a public static var debugMode on a global Environment class instance to true. Then all my classes can see that we are in a testing environment, and will act accordingly.

我使用名为“TestingEnvironment”的flashvar。在应用程序启动时,我检查loaderInfo.parameters以查看它是否设置为'true'(字符串文字,而不是布尔值),如果是,我将全局Environment类实例上的公共静态var debugMode设置为true。然后我的所有课程都可以看到我们处于测试环境中,并会采取相应的行动。

Also, since I use different page code to embed for testing and production, I expect the flashvar never to end up in the production page embed. And if it does, it's simple to turn off, no recompile needed.

此外,由于我使用不同的页面代码嵌入测试和生产,我希望flashvar永远不会在生成页面嵌入中结束。如果确实如此,关闭很简单,不需要重新编译。


推荐阅读
author-avatar
冰月雪镜樱1993
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有