/**
* thanks for http://nsdevaraj.wordpress.com/2008/10/16/avm1movie-controller-in-flex/
* and http://troyworks.com/blog/2007/09/17/avm2loader-converting-avm1-to-avm2/
*
* AVM1MovieProxy
*
* modified by sban 2009/2/21
* http://blog.sban.com.cn/
*/
package sban.flexStudy.avm1to2
{
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 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.loadBytes(inputBytes);
}
private function loadCompleteHandler(event : Event) : void
{
event.currentTarget.removeEventListener(Event.COMPLETE, loadCompleteHandler);
_movieClip = _loader.content as MovieClip;
_isReady = true;
dispatchEvent(new Event(Event.COMPLETE));
if(!autoPlay) stop();
_movieClip.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
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, 8);
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));
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:avm1to2="sban.flexStudy.avm1to2.*" fontSize="12">
<mx:Script>
<![CDATA[
[Bindable]
private var totalFrames : int = 0;
[Bindable]
private var currentFrame : int = 0;
]]>
</mx:Script>
<mx:Label x="19" y="22" text="This's a avm1 swf:"/>
<mx:Canvas width="135" height="40" backgroundColor="#D9DCE2" x="19" y="48">
<avm1to2:AVM1MvoieProxy id="avm1" url="sban/flexStudy/avm1to2/avm1.swf"><!--是Avm1的视频-->
<avm1to2:complete>
<![CDATA[
totalFrames = avm1.totalFrames;
]]>
</avm1to2:complete>
<avm1to2:enterFrame>
<![CDATA[
currentFrame = avm1.currentFrame;
]]>
</avm1to2:enterFrame>
</avm1to2:AVM1MvoieProxy>
</mx:Canvas>
<mx:Label x="19" y="111" text="current frame:{currentFrame}"/>
<mx:Label x="19" y="137" text="total frames:{totalFrames}"/>
<mx:Button x="19" y="172" label="play" click="avm1.play()"/>
<mx:Button x="19" y="202" label="stop" click="avm1.stop()"/>
<mx:Button x="19" y="232" label="gotoAndStop(10)" click="avm1.gotoAndStop(1000)"/>
<mx:Button x="19" y="262" label="gotoAndPlay(20)" click="avm1.gotoAndPlay(20)"/>
</mx:Application>
原文:http://blog.sban.com.cn/2009/02/21/how-to-load-and-play-stop-avm1-swf-in-as3-or-flex.html
分享到:
相关推荐
`AVM1Movie_To_MovieClip`这个类很可能是作者为了弥补AS3原生不支持AMV1格式而编写的。这个类可能包含了读取AMV1视频数据、解码、并将每一帧转换为AS3中的BitmapData,然后利用DisplayObject容器的功能组合成...
由DevTrip Video开发人员及其贡献者提供支持的 Flash AS 3 (AVM2) 视频播放器 [Need independent contributors and Investors for TBD section.] 目标 这个包提供了一个可重用的视频播放器组件,可以很容易地与任何...
DTV-FLASH-AS2 由DevTrip Video开发人员及其贡献者提供支持的 Flash AS 2 (AVM1) 视频播放器。 [Need independent contributors and Investors for TBD section.]目标这个包提供了一个可重用的视频播放器组件,可以...
- **性能提升**:AS3 相比之前的版本有显著的性能改进,这得益于新的虚拟机 AVM2。 - **内存管理**:提供了垃圾回收机制,使得开发者不再需要手动管理内存分配和释放。 - **面向对象编程(OOP)**:支持类、接口、...
AS3的执行效率显著高于AS2,这主要得益于其新的虚拟机——Adobe虚拟执行环境(AVM2)。AVM2通过即时编译技术将AS3代码转换为机器码,大大提高了执行速度。此外,AS3还提供了更高效的内存管理机制,减少了垃圾回收的...
3. **性能提升**:由于AS3.0运行在Flash Player的ActionScript Virtual Machine 2(AVM2)上,它的执行速度比AS2.0快很多,更适合开发复杂的互动应用。 4. **事件驱动模型**:AS3.0采用事件驱动编程模型,允许...
- **性能提升:** ActionScript 3.0 使用了更高效的虚拟机 AVM3 (ActionScript Virtual Machine),这大大提高了代码执行速度。 - **面向对象编程支持:** 它提供了更强大的类和继承机制,便于创建可扩展和易于维护的...
- **AVM2虚拟机**: AVM2是专门为AS3设计的虚拟机,它比前代AVM1更为高效且功能强大。这主要得益于AVM2对现代编程语言特性的支持以及更好的优化机制。 - **兼容性**: 为了确保向后兼容性,即使是在支持AVM2的Flash ...
6. **性能提升**:AS3的执行速度比前一版本快得多,这得益于其全新的虚拟机(AVM2)和更强的类型检查。 7. **XML和JSON支持**:AS3内置了处理XML和JSON数据的能力,方便与服务器进行数据交换,支持数据驱动的应用...
*.AVM;*.AVS;*.DAT;*.FLV;*.MKV;*.MOV;*.MP4;*.MPEG;*.MPG;*.NSV; *.OGM;*.RM;*.RMVB;*.TP;*.TS;*.VOB;*.WMV;)。 偶偶企业视窗主要更新: 1、增加支持X264格式的高清直播; 2、强大后台管理系统。
- **高性能**:由于采用了新的虚拟机(AVM2),ActionScript 3.0在执行速度上有显著提升。 - **强大的类库**:提供了丰富的API,支持各种多媒体处理、网络通信等功能。 - **内存管理**:采用自动垃圾回收机制,简化...
1. **ActionScript虚拟机(AVM2)**:AVM2是Lightspark中的关键组件,用于解释和执行ActionScript 3代码。熟悉ActionScript语言和虚拟机的工作原理对于理解Lightspark至关重要。 2. **SWF文件格式**:了解SWF文件的...
4. 音频和视频处理:AS3.0支持流媒体播放、音视频录制和编辑,为多媒体应用提供了强大支持。 四、学习资源与工具 - Adobe Animate CC(前身为Flash Professional)是主要的开发工具,用于创建和调试AS3.0项目。 - ...
TVP5150AM1 视频解码芯片 TVS TVS保护 ULN2003L 驱动芯片 USB USB接口 USB_M MicroUSB接口 VS10XX 音频解码芯片 W25QXX SPI FLASH XATLS 贴片有源晶振 XTAL 晶振 XTAL-3PIN 贴片晶振 XTAL_SM 圆柱晶振 PCB封装列表 ...
- 800D01-VSW : FBAS 输入端1无视频信号或无同步信号,34537km,无故障类型可用; - B7F841 CIC : FBAS 输入端1视频或同步信号不存在,34537km,无故障类型可用; - E2D401-信息(车辆状态,0X3A0):有故障,...
4. **性能提升**:由于采用了新的虚拟机(AVM2),AS3.0运行速度显著提高,与早期版本相比,可以处理更复杂的应用。 5. **增强的图形处理**:ActionScript 3.0提供了强大的图形API,可以进行像素级操作,创建复杂的...
* is of the correct type, so we can use it as a struct. * current_location is a void pointer so we can use it * to calculate addresses. */ current_location_mcb = (struct mem_control_...
- **AVM1Movie**:表示ActionScript 1.0/2.0中创建并已加载的SWF文件。 - **Bitmap**:用于加载和显示位图图像,并可以与BitmapData类结合创建自定义图像。 - **MorphShape**:用于形状补间动画,但在AS3中不能...
- 高性能:利用AVM2虚拟机执行,性能大幅提升。 #### 二、Flex 概述 - **定义**:Flex 是一个开源框架,用于构建和维护复杂Web应用程序的客户端。 - **特点**: - 使用MXML和ActionScript 3.0编写。 - 支持数据...