flash 屏幕更新

转自:http://chaimzane.javaeye.com/blog/320349

lash 中的屏幕更新主要分为两种:
   1.scheduled update (主要)
   2.post-event update

一。scheduled update

   flash中的帧分为两种
    a. Flash Player Frames
   b. SWF Frames

   swf 帧就是我们在使用Flash Ide是看到的时间线的帧,包括帧上的内容和帧上的代码
   Flash Player帧的概念,是flash执行时的帧的概念,包括运行该swf帧上的代码和render 帧上的内容输出,和代码生成内容输出

下面的图呢过说明两者之间的关系:

 

其中 screenUpdate check() 中,判断为需要render 的条件   1. frame 中的内容被创建或修改   2.frame script 创建了新的 visual 内容 或修改   3.在等待期间,执行了list ener函数,并创建会修改 了 visual 内容 这里的屏幕render不会打断现有的代码执行而去执行一次 render ,她一定会在你所有的代码都执行完成后才会渲染。 二。Post-Event Screen Update   但是当一些visiual的东西的改变是由 mouse keyboard 来触发的,这样的话,还要等到屏幕render时才会显示 出变化,这会让程序看起来不是 很流畅。为了避免这样的问题,可以使用它,updateAfterEvent   updateAfterEvent可以分为两种类型,一种是手动触发的,比如,MouseEvent的 event.updateAfterEvent,执行后,会出发屏幕的screenUpdate check(), 并立刻渲染相关内容,用到updateAfterEvent还有,keyDownListener的 event.updateAfterEvent,TimerEvent的event.updateAfterEvent。   还有一种是自动触发的,比如如下:                1.当鼠标移到/出,继承自 Sprite时自动触发 updateAfterEvent              2.按下/释放 鼠标左键(右撇子)时自动触发 updateAfterEvent              3.Using the spacebar or Enter key to activate an instance of a class that inherits from Sprite 三。Optimization with the Event.RENDER Event   当以下条件都为true时Flash runtime才会出发Event.RENDER,             1.The Flash runtime is about to check if the screen needs updating (whether due to a frame passing or an updateAfterEvent( ) call).           2.The programmer has invoked stage.invalidate( ). (stage.invalidate( ) is the programmer’s way of asking the Flash runtime to dispatch the Event.RENDER event the next time a screen-update check occurs). 就是当flash 即将要checkUpdate 的时候,包括scheduled update 触发的和Post-Event Screen Update触发的,还有个就是要 调用 stage。invalidate() 利用这用技术,我可以用Event.RENDER事件 来 优化程序,详见 Essential.ActionScript.3.0.pdf 463页。在Flex中的 a.callbackLater(),还有就是LayOutManger的机制也采用这用原理。有的人对 invalidateProperties(), invalidateSize(),invalidateDisplayList(),几个函数执行的原理和时间 不是很清楚,看完那个源代码很能会对你 有点帮助。。。

原文地址:https://www.cnblogs.com/sevenyuan/p/1750044.html