如何让Flash“和别人玩得好”?

发布于 2024-08-29 20:04:25 字数 1711 浏览 7 评论 0 原文

家人怎么了。所以这不是一个关于内存管理方案的问题;而是一个关于内存管理方案的问题。对于那些可能不知道的人,Flash 虚拟机通过使用引用计数和标记和清除来依赖垃圾回收(要详细了解这些主题,请查看 Grant Skinner 的 文章演示文稿)。是的,Flash 还提供了“删除”运算符,它可以(不幸的是只能)用于删除动态对象的属性。

我想知道的是如何使Flash程序在后台运行时(例如保存加载内容或远程通信)不再继续消耗CPU和内存。这个问题的动机部分来自苹果公司对交叉编译应用程序的禁令(在其 SDK 4 中),因为它们不按照 iPhone OS 4 核心的多任务处理 功能的预期运行。我的目的不仅仅是制作能够“通过测试”的 Flash 程序就像 iPhone OS 4 中的多任务处理一样,而且还只是为了制作更好(表现更好)的 Flash 程序。

换句话说,Flash 应用程序如何模仿 iPhone OS 4 的多任务处理功能? Flash API 是否为开发人员提供了在其他程序运行时将其应用程序置于“睡眠”状态,然后以同样快的速度“唤醒”它们的方法?

在我们自己的程序中,我们可能会做一些粗略的事情,例如检测用户何时闲置(没有鼠标移动或按键)四秒钟:(

var idle_id:uint = setInterval(4000, pause_program);
var current_movie_clip:MovieClip;
var current_frame:uint;

...

// on Mouse move or key press...
clearInterval(idle_id);
idle_id = setInterval(4000, pause_program);

...

function pause_program():void
{
 current_movie_clip = event.target as MovieClip;
 current_frame = current_movie_clip.currentFrame;
 MovieClip(root).gotoAndStop("program_pause_screen");
}

在程序暂停屏幕上)

resume_button.addEventListener(MouseEvent.CLICK, resume_program);

function resume_program(event:MouseEvent)
{
 current_movie_clip.gotoAndPlay(current_frame);
}

如果这是正确的想法,那么什么是最好的检测应用程序是否应被搁置的方法?

而且,更重要的是,Flash Player 是否有可能检测到其某些正在运行的程序处于空闲状态,并类似地搁置它们,直到用户执行恢复它们的操作?

(请随意回答我提出的许多问题。)

What up fam. So this isn't a question asking about memory management schemes; for those of you who may not know, the Flash Virtual Machine relies on garbage collection by using reference counting and mark and sweep (for good coverage of these topics, check out Grant Skinner's article and presentation). And yes, Flash also provides the "delete" operator, which can (unfortunately only) be used to remove the properties of dynamic objects.

What I want to know is how to make it so that Flash programs don't continue to consume CPU and memory while running in the background (save loading content or communicating remotely, for example). The motivation for this question comes in part from Apple's ban on cross compiled applications (in its SDK 4) on the grounds that they do not behave as predicted with the multitasking feature central to iPhone OS 4. My intention is not only to make Flash programs that will 'pass muster' as far as multitasking in iPhone OS 4, but also to simply make better (behaving) Flash programs.

Put another way, how might a Flash application mimic the multitasking feature of iPhone OS 4? Does the Flash API provide the means for a developer to put their applications to 'sleep' while other programs run, and then to 'awaken' them just as quickly?

In our own program, we might do something as crude as detecting when the user has been idle (no mouse motion or key press) for (say) four seconds:

var idle_id:uint = setInterval(4000, pause_program);
var current_movie_clip:MovieClip;
var current_frame:uint;

...

// on Mouse move or key press...
clearInterval(idle_id);
idle_id = setInterval(4000, pause_program);

...

function pause_program():void
{
 current_movie_clip = event.target as MovieClip;
 current_frame = current_movie_clip.currentFrame;
 MovieClip(root).gotoAndStop("program_pause_screen");
}

(on the program pause screen)

resume_button.addEventListener(MouseEvent.CLICK, resume_program);

function resume_program(event:MouseEvent)
{
 current_movie_clip.gotoAndPlay(current_frame);
}

If that's the right idea, what's the best way to detect that an application should be shelved?

And, more importantly, is it possible for Flash Player to detect that some of its running programs are idle, and to similarly shelve them until the user performs an action to resume them?

(Please feel free to answer as much or as little of the many questions I've posed.)

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

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

发布评论

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

评论(2

涙—继续流 2024-09-05 20:04:25

基本上,您可以使用 < code>Event.ACTIVATEEvent.DEACTIVATE 来了解您的应用何时失去焦点。

除此之外,我建议您除了纯粹的动画之外不要使用 Flash IDE,而是使用以编程为中心的 ActionScript IDE。 Flash IDE 的设计目的不是为了提高效率,而是为了易于使用。为了进行适当的优化,您需要以编程方式执行操作,以保持对应用程序的完全控制。

至于 iPhone:这不是你应该关心的。如果 adobe 找到一种在 iPhone 上使用 flash 的方法,我想他们的抽象层将尽可能地适应 iPhone 操作系统。原生 Flash 播放器实现的内部工作原理绝对不会向您公开,因为它需要大量的 API 更新,甚至可能需要新的操作码以及对您不应该在沙盒环境中访问的层的非常直接的访问,因为flash播放器是。

basically, you can use Event.ACTIVATE and Event.DEACTIVATE to find out when your app loses focus.

other than that, I advise you not to use the Flash IDE for anything but pure animation and use a programming centric actionscript IDE. Flash IDE is not designed for efficiency but for ease of use. For proper optimisation you need to do things programmatically in order to maintain full control over your app.

as to the iPhone: that is nothing you should concern yourself with. if adobe ever figures out a way to get flash on the iPhone, I suppose their abstraction layer will be adapted to work as good as possible with the iPhone OS. The inner workings of the native flash player implementation will most definitely not be exposed to you, since it would require a huge API update, maybe even new opcodes and very direct access to layers you shouldn't be allowed to access in a sandboxed environement as the flash player is.

牵强ㄟ 2024-09-05 20:04:25

好吧,我不会很快就为 iPhone 操作系统上的 Flash 屏住呼吸。

http://www.engadget.com/2010/04/21/adobe-halts-investment-in-iphone-specific-flash-dev-tools-has-a/

Well I wouldn't hold your breathe for flash on iphone os anytime soon.

http://www.engadget.com/2010/04/21/adobe-halts-investment-in-iphone-specific-flash-dev-tools-has-a/

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