[flex] 请教如何将AS2.0(或1.0)编写的SWF转换为AS3.0的
fw2003
2009-09-08
现在项目中需要引用外部一个写好的SWF,无奈美工水平不够,自己也做不出好的动画效果,因此在网上找了一个比较符合的SWF.但是在使用SwfLoader的时候发现能够加载但是无法正常显示.查了下,就是Flash Player 9(AS3.0)可以加载以前的所有版本的swf,但是只是简单加载,不能访问AS2.0(或1.0)的swf内部变量&函数,无法交互。据说使用ExternalInterface这个类可以和AS1.0或2.0通讯,但是找了下网上的例子都是调用JS的.
可能是我异想天开了,请教各位.能不能用什么方式可以将AS2.0(或1.0)编写的SWF转换为AS3.0的,越简单越好,如果能够不会AS2.0都可以那最好..... |
|
dazhilao
2009-10-08
|
|
pzmayf
2009-10-09
可以用AVM1MvoieProxy 这是一个老外写的as,你可以到网上搜下
package { import flash.display.Loader; import flash.display.MovieClip; import flash.errors.EOFError; import flash.events.Event; import flash.events.IOErrorEvent; import flash.events.SecurityErrorEvent; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLRequest; import flash.utils.ByteArray; import flash.utils.Endian; import mx.core.UIComponent; [Event(name="enterFrame", type="flash.events.Event")] [Event(name="complete", type="flash.events.Event")] [Event(name="ioError", type="flash.events.IOErrorEvent")] [Event(name="securityError", type="flash.events.SecurityErrorEvent")] public class AVM1MvoieProxy extends UIComponent { public function AVM1MvoieProxy() { this.addChild(_loader); } private var _urlLoader : URLLoader; private var _loader:Loader = new Loader(); private var _isReady : Boolean = false; private var _movieClip : MovieClip; public var url : String; public var autoPlay : Boolean = false; public function get currentFrame() : int { return isReady ? _movieClip.currentFrame : 0; } public function get totalFrames() : int { return isReady ? _movieClip.totalFrames : 0; } public function get isReady() : Boolean { return _isReady; } public function nextFrame() : void { if(isReady) _movieClip.nextFrame(); } public function prevFrame() : void { if(isReady) _movieClip.prevFrame(); } public function nextScene() : void { if(isReady) _movieClip.nextScene(); } public function prevScene() : void { if(isReady) _movieClip.prevScene(); } public function stop() : void { if(isReady) _movieClip.stop(); } public function play() : void { if(isReady) _movieClip.play(); } public function gotoAndStop(frame : Object, scene : String = null) : void { if(isReady) _movieClip.gotoAndStop(frame, scene); } public function gotoAndPlay(frame : Object, scene : String = null) : void { if(isReady) _movieClip.gotoAndPlay(frame, scene); } override protected function initializationComplete():void { super.initializationComplete(); if(url) load(url); } public function setContentHeight(h:Number){ this._movieClip.height=this._movieClip.height+h; } public function setContentWidth(w:Number){ this._movieClip.width=this._movieClip.height+w; } public function load(url : String = null):void { var path : String = url ? url : this.url; if(!path) return; _urlLoader = new URLLoader(); _urlLoader.dataFormat = URLLoaderDataFormat.BINARY; _urlLoader.addEventListener(Event.COMPLETE, completeHandler); _urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); _urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); _urlLoader.load( new URLRequest(path)); } private function completeHandler(event:Event):void { event.currentTarget.removeEventListener(Event.COMPLETE, completeHandler); var inputBytes:ByteArray = ByteArray(_urlLoader.data); inputBytes.endian = Endian.LITTLE_ENDIAN; if (isCompressed(inputBytes)) { uncompress(inputBytes); } var version:uint = uint(inputBytes[3]); if (version <= 10) { if (version == 8 || version == 9 || version == 10){ flagSWF9Bit(inputBytes); } else if (version <= 7) { insertFileAttributesTag(inputBytes); } updateVersion(inputBytes, 9); } _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler); _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); _loader.loadBytes(inputBytes); } private function loadCompleteHandler(event : Event) : void { event.currentTarget.removeEventListener(Event.COMPLETE, loadCompleteHandler); _movieClip = _loader.content as MovieClip; _isReady = true; this.setActualSize(_movieClip.width,_movieClip.height); //this.invalidateSize(); //this.invalidateDisplayList(); dispatchEvent(new Event(Event.COMPLETE)); if(!autoPlay) stop(); _movieClip.addEventListener(Event.ENTER_FRAME, enterFrameHandler); } // override protected function measure():void { // super.measure(); // if(_isReady){ // this.measuredMinHeight = this.measuredHeight = _movieClip.height; // this.measuredMinWidth = this.measuredWidth = _movieClip.width; // // } // // } private function enterFrameHandler(event : Event) : void { dispatchEvent(event); } /** * * @param bytes * @return * */ private function isCompressed(bytes:ByteArray):Boolean { trace(bytes.toString()); return bytes[0] == 0x43; } private function uncompress(bytes:ByteArray):void { var cBytes:ByteArray = new ByteArray(); cBytes.writeBytes(bytes,; bytes.length = 8; bytes.position = 8; cBytes.uncompress(); bytes.writeBytes(cBytes); bytes[0] = 0x46; cBytes.length = 0; } private function getBodyPosition(bytes:ByteArray):uint { var result:uint = 0; result += 3; // FWS/CWS result += 1; // version(byte) result += 4; // length(32bit-uint) var rectNBits:uint = bytes[result] >>> 3; result += (5 + rectNBits * 4) / 8; // stage(rect) result += 2; result += 1; // frameRate(byte) result += 2; // totalFrames(16bit-uint) return result; } private function findFileAttributesPosition(offset:uint, bytes:ByteArray):uint { bytes.position = offset; try { for (;;) { var byte:uint = bytes.readShort(); var tag:uint = byte >>> 6; if (tag == 69) { return bytes.position - 2; } var length:uint = byte & 0x3f; if (length == 0x3f) { length = bytes.readInt(); } bytes.position += length; } } catch (e:EOFError) { } return NaN; } private function flagSWF9Bit(bytes:ByteArray):void { var pos:uint = findFileAttributesPosition(getBodyPosition(bytes), bytes); if (!isNaN(pos)) { bytes[pos + 2] |= 0x08; } } private function insertFileAttributesTag(bytes:ByteArray):void { var pos:uint = getBodyPosition(bytes); var afterBytes:ByteArray = new ByteArray(); afterBytes.writeBytes(bytes, pos); bytes.length = pos; bytes.position = pos; bytes.writeByte(0x44); bytes.writeByte(0x11); bytes.writeByte(0x08); bytes.writeByte(0x00); bytes.writeByte(0x00); bytes.writeByte(0x00); bytes.writeBytes(afterBytes); afterBytes.length = 0; } private function updateVersion(bytes:ByteArray, version:uint):void { bytes[3] = version; } private function ioErrorHandler(event:IOErrorEvent):void { dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR)); } private function securityErrorHandler(event:SecurityErrorEvent):void { dispatchEvent(new SecurityErrorEvent(SecurityErrorEvent.SECURITY_ERROR)); } } } |
|
pzmayf
2009-10-09
对了,里面有些代码我可能改了,你最好找到原代码
|
|
地势坤
2010-03-09
你好!我也遇到了这个问题,请问你的解决了吗?如果解决了告诉我一下解决吧,我都快被折腾死了,我的邮箱是tt_peng@126.com。qq :243711049
谢谢了 |