How to make Flash 'play well with others'?
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' 开发者_StackOverflowthem 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.)
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.
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/
精彩评论