Created
April 9, 2013 13:27
-
-
Save fireyang/5345683 to your computer and use it in GitHub Desktop.
enter frame callback without events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import flash.display.Loader; | |
import flash.display.MovieClip; | |
import flash.events.Event; | |
import flash.system.LoaderContext; | |
import flash.utils.ByteArray; | |
public class Framesync { | |
// Raw SWF bytecode (contains two empty keyframes on the main timeline) | |
static private const bytecode:Vector.<int> = new <int>[ | |
0x46, 0x57, 0x53, 0x11, 0x36, 0x00, 0x00, 0x00, | |
0x30, 0x0A, 0x00, 0xA0, 0x00, 0x01, 0x02, 0x00, | |
0x44, 0x11, 0x08, 0x00, 0x00, 0x00, 0x43, 0x02, | |
0xFF, 0xFF, 0xFF, 0xBF, 0x15, 0x05, 0x00, 0x00, | |
0x00, 0x01, 0x00, 0x30, 0x00, 0x00, 0x7F, 0x10, | |
0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, | |
0x40, 0x00, 0x40, 0x00, 0x00, 0x00 | |
]; | |
// Holds the parsed SWF file | |
private var loader:Loader = new Loader(); | |
// Function to call when the runtime enters a new frame | |
private var callback:Function = null; | |
// Constructor | |
public function Framesync( callback:Function ) { | |
var i:int = 0; | |
var n:int = bytecode.length; | |
var b:ByteArray = new ByteArray(); | |
var c:LoaderContext = new LoaderContext(); | |
while( i < n ) { | |
b[i] = bytecode[i]; | |
i++; | |
} | |
c.allowCodeImport = true; | |
loader.loadBytes( b, c ); | |
loader.contentLoaderInfo.addEventListener( Event.INIT, initialize ); | |
private::callback = callback; | |
} | |
// Called when the SWF bytecode has been parsed | |
private function initialize( e:Event ):void { | |
MovieClip(loader.content).addFrameScript( 0, callback, 1, callback ); | |
} | |
}// EOC | |
} |
使用方式:
const fs:Framesync = new Framesync( update );
function update():void { ... }
这也是靠加载进来的swf的enterframe机制的啊...看不出有什么区别呢..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
地址 https://plus.google.com/u/0/102163575299947413367/posts/QETP3j1xkTy