开始不清楚, 一直尝试想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之前的微妙关系的更多相关文章

  1. Go语言学习——彻底弄懂return和defer的微妙关系

    疑问 前面在函数篇里介绍了Go语言的函数是支持多返回值的. 只要在函数体内,对返回值赋值,最后加上return就可以返回所有的返回值. 最近在写代码的时候经常遇到在return后,还要在defer里面 ...

  2. JS Flex交互:html嵌套Flex(swf)

    一.html页面嵌套Flex需要用到 swfobject.js swfobject的使用是非常简单的,只需要包含 swfobject.js这个js文件,然后在DOM中插入一些简单的JS代码,就能嵌入F ...

  3. Redis的Time Event与File Event的微妙关系

    redis里设计了两类事件,一类是file event,一类是time event. 其中file event主要为网络事件而设计,而time event为一些后台事件设计. 在两类事件的管理设计上, ...

  4. STL标签与EL表达式之间的微妙关系

    很高兴,今天能和大家分享刚学的一些新知识.我们在java开发过程中经常会在jsp中嵌入一些java代码,比如<%=request.getParameter("id")%> ...

  5. Java学习——JSTL标签与EL表达式之间的微妙关系

    原文总结的太好了,忍不住记录.转发. 原文地址:http://blog.csdn.net/u010168160/article/details/49182867 目录(?)[-] 一EL表达式 EL相 ...

  6. 迭代器,生成器(generator)和Promise的“微妙”关系

    需要Promise源码版的朋友:传送链接 本文主要讲述(iterator)和生成器*/yield之间的联系和各自的用法,以及生成器的高配版本aysnc/await的使用. 大纲: 迭代器(iterat ...

  7. flash、flex builder、flash builder、 air的关系

    flash VS flex builder flash被adobe收购的时候是flash8,已经可以AS2面向对象了. 而被adobe收购后,adobe准备把flash打造成一个开发工具.就比如JBU ...

  8. jQuery Webcam Plugin jscam.swf文件反编译工具使用说明

    jQuery webcam plugin是一个在ie,firefox,chrome下都可以用的摄像头摄像及拍照用的插件. (http://www.xarg.org/project/jquery-web ...

  9. 【咸鱼教程】TextureMerger1.6.6 一:Egret MovieClip的制作和使用

    几个月没写代码了.然后突然用到TextureMerger,发现不会用序列图做动画了... 于是写下过程,以防忘记... MovieClip主要是用于游戏中的动画制作和播放.支持swf.gif.序列图等 ...

随机推荐

  1. linux系统编程之lseek帮助文档

    通过man 2 lseek可以查看linux中的系统函数lseek函数的帮助文档,为了更好的学习,我把这些重要内容翻译过来 NAME lseek - reposition read/write fil ...

  2. 【Java学习笔记】静态导入

    package p2; //import static java.util.Collections.max; import java.util.ArrayList; import static jav ...

  3. 用Java导出为excel表格

    导出的是最基础的excel表格,没有任何样式. <input type="button" value="输出到Excel" onclick='output ...

  4. Hibernate-list()与iterate()方法的区别

    对于list方法而言,实际上Hibernate是通过一条Select SQL获取所有的记录.并将其读出,填入到POJO中返回.而iterate 方法,则是首先通过一条Select SQL 获取所有符合 ...

  5. 进阶——scrapy登录豆瓣解决cookie传递问题并爬取用户参加过的同城活动©seven_clear

    最近在用scrapy重写以前的爬虫,由于豆瓣的某些信息要登录后才有权限查看,故要实现登录功能.豆瓣登录偶尔需要输入验证码,这个在以前写的爬虫里解决了验证码的问题,所以只要搞清楚scrapy怎么提交表单 ...

  6. Good-Bye

    嘛……以一种奇怪的姿势滚粗了…… 如果这个Blog能给未来的OIer们一些帮助的话,它也不枉存在了…… 我的OI之路也能以另一种形式延续下去吧…… 也许能搞ACM的话会再开?…… 不管怎么说,各位再见 ...

  7. Eclipse创建Android模拟器创建选项解释

  8. vi命令模式下快速注释代码的方法

    进入http://www.vim.org/scripts/script.php?script_id=1528 点击这个链接下载comments.vim这个插件 然后把它放入到./vim/plugin下 ...

  9. php tools for visual studio 2013 完美 破解 Cracker

    PHP Tools for Visual Studio 2013,这个是 目前在 Visual Studio 2010/2012/2013 中 下最好用的php插件了,  破解 好的 Cracker  ...

  10. 在ubuntu上配置nginx+php+mysql+phpmyadmin

    1.先更新ubuntu系统 更新命令 sudo apt-get update sudo apt-get upgrade 2 添加ubuntu nginx更新源镜像 cd /etc/apt/ sudo ...