flex swf和movieclip之前的微妙关系
开始不清楚, 一直尝试想load图片一样加载一个swftools转换的swf,然后在尝试转换成movieclip的时候,总是报错, avmiMovieClip 不能转换成movieclip之类的。
但为什么有的swf可以轻松转换成movieclip呢?
后面我明白这两种movieclip根本就是不同存储格式了,—— 虽然都是swf后缀
关于movieclip ,我一直不太明白,其实它相当的有用。
package
{
import flash.display.Loader;
import flash.errors.EOFError;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
import flash.utils.Endian; import mx.controls.Alert; public class ForcibleLoader
{
public function ForcibleLoader()//loader:Loader
{
this.loader = new Loader(); _stream = new URLStream();
_stream.addEventListener(Event.COMPLETE, completeHandler);
_stream.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
_stream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
} private var _loader:Loader;
private var _stream:URLStream;
private var _callback:Function; public function get loader():Loader
{
return _loader;
} public function set loader(value:Loader):void
{
_loader = value;
} public function load(url:String, callback:Function):void
{
var request:URLRequest = new URLRequest(url);
this._callback = callback;
_stream.load(request); // var urlRequest:URLRequest = new URLRequest("adobe1231.swf");
// var urlLoader:URLLoader=new URLLoader();
// urlLoader.addEventListener(Event.COMPLETE,completeHandler);
// urlLoader.dataFormat=URLLoaderDataFormat.BINARY; } private function completeHandler(event:Event):void
{
var inputBytes:ByteArray = new ByteArray();
_stream.readBytes(inputBytes);
// _stream.close();
inputBytes.endian = Endian.LITTLE_ENDIAN; if (isCompressed(inputBytes)) {
uncompress(inputBytes);
} var version:uint = uint(inputBytes[]); // if (version < 9) {
// updateVersion(inputBytes, 9);
// }
// if (version > 7) {
// flagSWF9Bit(inputBytes);
// }
// else {
// insertFileAttributesTag(inputBytes);
// } if (version <= ) {
if (version == || version == )
{
flagSWF9Bit(inputBytes);
}else if (version <= )
{
insertFileAttributesTag(inputBytes);
}
updateVersion(, inputBytes);
} this.loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress)
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError)
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete) var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain); loader.loadBytes(inputBytes, context);//new LoaderContext(true, ApplicationDomain.currentDomain));
//loader.addEventListener(Event.COMPLETE, loaderComplete)
} private function loadComplete(evt:Event):void
{
Alert.show("sssssssssssss");
//_callback(loader.content as MovieClip);
}
private function loadProgress(evt:ProgressEvent):void
{
trace(" ProgressEvent : " +evt.bytesLoaded + " / " +evt.bytesTotal);
if(evt.bytesLoaded == evt.bytesTotal) { //_callback(loader.content as MovieClip);
}
}
private function onError(evt:IOErrorEvent):void
{
Alert.show(" ProgressEvent ");
} private function isCompressed(bytes:ByteArray):Boolean
{
return bytes[] == 0x43;
} private function uncompress(bytes:ByteArray):void
{
var cBytes:ByteArray = new ByteArray();
cBytes.writeBytes(bytes, );
bytes.length = ;
bytes.position = ;
cBytes.uncompress();
bytes.writeBytes(cBytes);
bytes[] = 0x46;
cBytes.length = ;
} // 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;
// } public function flagSWF9Bit(bytes:ByteArray):void
{
var pos:int = findFileAttributesPosition(getBodyPosition(bytes), bytes); if (pos != -) {
bytes[pos + ] |= 0x08;
}
else {
insertFileAttributesTag(bytes);
}
} private function findFileAttributesPosition(offset:uint, bytes:ByteArray):int
{
bytes.position = offset; try {
for (;;) {
var byte:uint = bytes.readShort();
var tag:uint = byte >>> ;
if (tag == ) {
return bytes.position - ;
}
var length:uint = byte & 0x3f;
if (length == 0x3f) {
length = bytes.readInt();
}
bytes.position += length;
}
}
catch (e:EOFError) {
} return -;
}
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 = ;
}
private function getBodyPosition(bytes:ByteArray):uint
{
var result:uint = ; result += ; // FWS/CWS
result += ; // version(byte)
result += ; // length(32bit-uint) var rectNBits:uint = bytes[result] >>> ;
result += ( + rectNBits * ) / ; // stage(rect) result += ; result += ; // frameRate(byte)
result += ; // totalFrames(16bit-uint) return result;
} public function updateVersion(version:uint, b:ByteArray):void
{
b[] = version;
} // 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
{
loader.contentLoaderInfo.dispatchEvent(event.clone());
} private function securityErrorHandler(event:SecurityErrorEvent):void
{
loader.contentLoaderInfo.dispatchEvent(event.clone());
}
}
}
无论如何, 下面的loadComplete就是没有执行,像是某个地方卡住了一样,但是、、、 我看了progess都是100%的。。 试过很多方式,还是一样结果。
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete)
但为什么其他方式就行了呢? 几乎是一样的写法啊?
package
{
import com.hurlant.crypto.Crypto;
import com.hurlant.crypto.symmetric.ICipher;
import com.hurlant.crypto.symmetric.IPad;
import com.hurlant.crypto.symmetric.PKCS5;
import com.hurlant.util.Hex; import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.errors.*;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.net.*;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
import flash.utils.Endian; import mx.controls.Alert;
import mx.controls.ProgressBar;
/**
*队列加载类
* @author Ryan_Leung
*
*/
public class LoaderManager
{
// public var _order:int = 0;
public var _loadOrder:int = ;
public var loadOrder_from:int = ;
public var loadOrder_to:int = ;
private var _callBack:Function;
public var _paths:Array = [];
private var _load:Loader;
private var _progressBar:ProgressBar;
private var _fristloadswfs:int; private var loadedSWFs:Array = []; private var noloadSWFs:Array = []; public var mc:MovieClip = null; public var bookdecrypt:String = "";
private var stream:URLStream = null; public function LoaderManager(progressBar:ProgressBar, fristloadswfs:int)
{
_loadOrder = ;
loadOrder_from = ;
loadOrder_to = fristloadswfs;
_progressBar = progressBar;
_fristloadswfs = fristloadswfs;
}
public function addPath(path:String):void
{
for(var i:int = ; i < _paths.length ; i++)
{
if(_paths.indexOf(path) > -)
return;
}
_paths.push(path);
}
public function getPath(pageNum:int):String
{
if(pageNum > _paths.length)
{
return "";
}
var ss:String = _paths[pageNum] ;
return ss;
//_load.load(new URLRequest(loadedSWFs[_loadOrder]) , new LoaderContext(true));
} /**
* 通过paths数组的索引找到路径path加载swf
* 加载某一个swf时候,需要同时确保其前后6个swf都已经加载上, 否则有问题。
*
*/
public function loadSwfById(fromOrder:int,toOrder:int, callBack:Function):void {
_loadOrder = fromOrder;
loadOrder_from = fromOrder;
loadOrder_to = toOrder;
start(callBack);// // call back when the load is finished! 调用了两次, 不知道合理不合理
} /**
* 在所有资源路径添加完之后、开始加载
*/
public function start(callBack:Function):void
{ // stream = new URLStream();
// stream.addEventListener(Event.COMPLETE,completeHandler_s);
// stream.addEventListener(ProgressEvent.PROGRESS,progressHandler);
// stream.addEventListener(IOErrorEvent.IO_ERROR,ioerrorHandler);
if(stream != null)
{
stream.close();
stream = null;
}
if(this.pbuf != null)
{
this.pbuf.clear(); }
_load = new Loader();
if(this.loader != null)
{
try {
this.loader.close();
} catch (err:Error) {
trace(err.message);
}
this.loader = null; } _callBack = callBack;
loading();
} private var urlReq:URLRequest = null;
public var buffer:ByteArray = null;
private var isencrty:Boolean = false;
private var pbuf:ByteArray = new ByteArray();
private var loaderCtx:LoaderContext = null;
public var loader:Loader = null;
private function progressHandler(event:ProgressEvent):void
{
//trace("progress ……");
this.stream.readBytes(this.pbuf,this.pbuf.length); }
public function isCompressed(bytes:ByteArray):Boolean
{
return bytes[] == 0x43;
}
private function ioerrorHandler(event:IOErrorEvent):void
{
trace("ioerror");
trace(event.text);
}
private function uncompress(bytes:ByteArray):void
{
var cBytes:ByteArray = new ByteArray();
cBytes.writeBytes(bytes, );
bytes.length = ;
bytes.position = ;
cBytes.uncompress();
bytes.writeBytes(cBytes);
bytes[] = 0x46;
cBytes.length = ;
}
private function completeHandler_s(event:Event):void
{
trace("Stream complete");
//解密 bookdecrypt ="s3@74$*K";
var decryptLen:int = this.pbuf.readInt();
var decryptStr:String = this.pbuf.readUTFBytes(decryptLen);
//trace(decryptLen,decryptStr);
var kdata:ByteArray = Hex.toArray(Hex.fromString(bookdecrypt));
var data:ByteArray = Hex.toArray(decryptStr);
var name:String = "simple-des-ecb";
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(name,kdata,pad);
pad.setBlockSize(mode.getBlockSize());
mode.decrypt(data); if(data==null)
{
onLoadComplete(event);
return;
}
this.buffer.endian = Endian.LITTLE_ENDIAN;
this.buffer.writeBytes(data);
//trace(Hex.fromArray(data));
this.pbuf.readBytes(this.buffer,this.buffer.length);
// // this.buffer = this.pbuf; if(isCompressed(this.buffer)) {
//trace("uncompress");
uncompress(this.buffer);
}
var version:uint = uint(this.buffer[]);
//trace(version,"ver");
if (version <= ) {
if (version == || version == )
{
flagSWF9Bit(this.buffer);
}else if (version <= )
{
insertFileAttributesTag(this.buffer);
}
updateVersion(,this.buffer);
}
//var result:DisplayObject = loader.content as DisplayObject;
//ResourceBox.setResource(_paths[_loadOrder] , result);
if(_loadOrder ==)
{
//_loadOrder =_loadOrder+1; }
//loading();
//_loadOrder++; this.loader = new Loader();
this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE,swfCompleteHandler);
this.loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,swfProgress);
this.loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR , onError);
this.loader.loadBytes(this.buffer,this.loaderCtx);
//this.loader.loadBytes(this.buffer); trace("正加载文件:"+_loadOrder); loadedSWFs.push(this.loader); }
private function onLoadComplete(event:Event):void
{
if (stream.connected)
{
var b:int;
try {
do {
b = stream.readByte();
pbuf.writeByte(b);
} while (true);
} catch (e:EOFError) {
//Alert.show(bytes.length.toString());
}
}
this.buffer.writeBytes(buffer);
this.loader.loadBytes(buffer);
}
private function swfProgress(event:ProgressEvent):void
{
//trace("swf progress");
//trace("正加载文件:"+_loadOrder);
if(mc != null)
{
//trace(mc.framesLoaded,mc.totalFrames);
}
}
private function swfCompleteHandler(event:Event):void
{
trace("swf complete"); //event.target.removeEventListener(Event.COMPLETE, this.swfCompleteHandler);
this.mc = event.target.content as MovieClip;
//this.loader.loadBytes(this.buffer,this.loaderCtx);
//var result:DisplayObject = loader.content as DisplayObject;
//ResourceBox.setResource(_paths[_loadOrder] , result); // if(_loadOrder == 0 || _progressBar.visible == true) // ??
// {
// _progressBar.visible = false;
_callBack(mc);
// }
_loadOrder=_loadOrder+; // _loadOrder =_loadOrder+1; ??
trace("已加载文件:"+_loadOrder);
//loading();
/*test */
//this.mc.trackAsMenu=true;
//flash.utils.setTimeout(tt,1000); } public function flagSWF9Bit(bytes:ByteArray):void
{
var pos:int = findFileAttributesPosition(getBodyPosition(bytes), bytes); if (pos != -) {
bytes[pos + ] |= 0x08;
}
else {
insertFileAttributesTag(bytes);
}
}
private function findFileAttributesPosition(offset:uint, bytes:ByteArray):int
{
bytes.position = offset; try {
for (;;) {
var byte:uint = bytes.readShort();
var tag:uint = byte >>> ;
if (tag == ) {
return bytes.position - ;
}
var length:uint = byte & 0x3f;
if (length == 0x3f) {
length = bytes.readInt();
}
bytes.position += length;
}
}
catch (e:EOFError) {
} return -;
}
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 = ;
}
private function getBodyPosition(bytes:ByteArray):uint
{
var result:uint = ; result += ; // FWS/CWS
result += ; // version(byte)
result += ; // length(32bit-uint) var rectNBits:uint = bytes[result] >>> ;
result += ( + rectNBits * ) / ; // stage(rect) result += ; result += ; // frameRate(byte)
result += ; // totalFrames(16bit-uint) return result;
} public function updateVersion(version:uint, b:ByteArray):void
{
b[] = version;
} private function loading():void
{
if(_loadOrder < loadOrder_from || _loadOrder > loadOrder_to || // 加载文件数现定于 loadOrder_from、loadOrder_to之间
_loadOrder > _paths.length - )
{ _progressBar.visible = false; _callBack(true);// ??
return;
}else
{ } // _load.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS , onProgress);
// _load.contentLoaderInfo.addEventListener(Event.COMPLETE , completeHandler);
// _load.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR , onError);
// if(this.buffer != null)
{
this.buffer.clear();
}
else
{
this.buffer = new ByteArray();
}
if(this.stream!=null)
{
this.stream.close();
} this.stream = new URLStream();
this.stream.addEventListener(Event.COMPLETE,completeHandler_s);
this.stream.addEventListener(ProgressEvent.PROGRESS,progressHandler);
this.stream.addEventListener(IOErrorEvent.IO_ERROR,ioerrorHandler); this.urlReq = new URLRequest(_paths[_loadOrder]);
trace(_paths[_loadOrder]);
this.stream.load(this.urlReq);
// _load.load(new URLRequest(_paths[_loadOrder]) , new LoaderContext(true));
}
private function onError(evt:IOErrorEvent):void
{
Alert.show(evt.toString() , "加载出错");
}
private function onProgress(evt:ProgressEvent):void
{
//trace("LoaderManager加载进度" + evt.bytesLoaded / evt.bytesTotal);
_progressBar.label = "加载中......";
_progressBar.setProgress(evt.bytesLoaded , evt.bytesTotal);
}
// private function completeHandler(evt:Event):void
// {
// var result:DisplayObject = _load.content as DisplayObject;
// ResourceBox.setResource(_paths[_loadOrder] , result);
// if(_loadOrder >= _paths.length - 1)
// {
// return;
// }
// if(_loadOrder == 0 || _progressBar.visible == true)
// {
// _progressBar.visible = false;
// _callBack();
// }
//
//
// } }
}
flex swf和movieclip之前的微妙关系的更多相关文章
- Go语言学习——彻底弄懂return和defer的微妙关系
疑问 前面在函数篇里介绍了Go语言的函数是支持多返回值的. 只要在函数体内,对返回值赋值,最后加上return就可以返回所有的返回值. 最近在写代码的时候经常遇到在return后,还要在defer里面 ...
- JS Flex交互:html嵌套Flex(swf)
一.html页面嵌套Flex需要用到 swfobject.js swfobject的使用是非常简单的,只需要包含 swfobject.js这个js文件,然后在DOM中插入一些简单的JS代码,就能嵌入F ...
- Redis的Time Event与File Event的微妙关系
redis里设计了两类事件,一类是file event,一类是time event. 其中file event主要为网络事件而设计,而time event为一些后台事件设计. 在两类事件的管理设计上, ...
- STL标签与EL表达式之间的微妙关系
很高兴,今天能和大家分享刚学的一些新知识.我们在java开发过程中经常会在jsp中嵌入一些java代码,比如<%=request.getParameter("id")%> ...
- Java学习——JSTL标签与EL表达式之间的微妙关系
原文总结的太好了,忍不住记录.转发. 原文地址:http://blog.csdn.net/u010168160/article/details/49182867 目录(?)[-] 一EL表达式 EL相 ...
- 迭代器,生成器(generator)和Promise的“微妙”关系
需要Promise源码版的朋友:传送链接 本文主要讲述(iterator)和生成器*/yield之间的联系和各自的用法,以及生成器的高配版本aysnc/await的使用. 大纲: 迭代器(iterat ...
- flash、flex builder、flash builder、 air的关系
flash VS flex builder flash被adobe收购的时候是flash8,已经可以AS2面向对象了. 而被adobe收购后,adobe准备把flash打造成一个开发工具.就比如JBU ...
- jQuery Webcam Plugin jscam.swf文件反编译工具使用说明
jQuery webcam plugin是一个在ie,firefox,chrome下都可以用的摄像头摄像及拍照用的插件. (http://www.xarg.org/project/jquery-web ...
- 【咸鱼教程】TextureMerger1.6.6 一:Egret MovieClip的制作和使用
几个月没写代码了.然后突然用到TextureMerger,发现不会用序列图做动画了... 于是写下过程,以防忘记... MovieClip主要是用于游戏中的动画制作和播放.支持swf.gif.序列图等 ...
随机推荐
- Linux echo, sort, sed 等一些命令总结
linux echo, sort, sed是初学linux shell script 的一些常用的命令.基本上来说,如果能够掌握了这些命令,我们就能写出一些不错的linux脚本.以下是我遇到的以下常用 ...
- 开园第一篇 - 论移动开发环境 IOS与Android的差异
首先,在真正写技术之前做个自我简介.本人08年开始学c语言 一年后,转vc++.开始接触MFC MFC做了两年.转眼11年了我考上了一个不知名的大专.搞C++发现没有市场了因为当时酷狗腾讯的软件已经日 ...
- MySQL执行计划解读
Explain语法 EXPLAIN SELECT …… 变体: 1. EXPLAIN EXTENDED SELECT …… 将执行计划“反编译”成SELECT语句,运行SHOW WARNINGS 可得 ...
- js call apply
参考文章:https://www.zhihu.com/question/20289071 引用:call 和 apply 都是为了改变某个函数运行时的 context 即上下文而存在的,换句话说,就是 ...
- React Native填坑之旅--class(番外篇)
无论React还是RN都已经迈入了ES6的时代,甚至凭借Babel的支持都进入了ES7.ES6内容很多,本文主要讲解类相关的内容. 构造函数 定义侦探类作为例子. ES5的"类"是 ...
- IIS 部署 node.js ---- 基础安装部署
一些可能有用的相关文章: https://blogs.msdn.microsoft.com/scott_hanselman/2011/11/28/window-iisnode-js/ http://b ...
- Cassandra对读写请求的处理机制
1 写请求: 单数据中心: 向所有副本发写请求, 所有副本都写数据, 只要有一致性水平指定数目的节点返回正确响应, 就认为写成功. 多数据中心: 客户端发起写数据请求后, 本地代理节点会把请求发给每个 ...
- Android学习地址
Google Android官方培训课程中文版http://hukai.me/android-training-course-in-chinese/
- cas+shiro统一注销原理解析
1,客户端发送一个注销请求到cas server,跟踪casorg.jasig.cas.CentralAuthenticationServiceImpl类的destroyTicketGrantingT ...
- HTTP笔记整理(1)
今天开始学习http协议,把自己从网上整理,自己理解的部分先发出来,共勉! (PS笔者小白一枚,如有理解性的错误,请指正告知,为感!!!) 一. HTTP协议概念 所谓的“协议”是指,计算机在通信网 ...