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.序列图等 ...
随机推荐
- 菜单的隐藏&显示
//还是先上万一老师的原代码 //隐藏与显示菜单Self.Menu := nil; {隐藏菜单} Self.Menu := MainMenu1; {显示菜单} //初一看到代码,我有点抓不到感觉的意思 ...
- STL库的内存配置器(allocator)
正在学习中,如果有错,还请多多指教,根据不断的理解,会进行更改,更改之前的样子都会保留下来,记录错误是最大的进步,嗯嗯! 具有次配置力的SGI空间配置器(SGI是STL的一种版本,也有其他的版本) 这 ...
- SpringMVC 的RequestMapping
Spring MVC之@RequestMapping 详解 2013-10-13 23:39 150698人阅读 评论(6) 收藏 举报 分类: Java 精华文章(161) 目录(?)[+] ...
- BZOJ4350: 括号序列再战猪猪侠
Description 括号序列与猪猪侠又大战了起来. 众所周知,括号序列是一个只有(和)组成的序列,我们称一个括号 序列S合法,当且仅当: 1.( )是一个合法的括号序列. 2.若A是合法的括号序列 ...
- checked属性
使用checked属性,你可以设置复选按钮和单选按钮默认被选中. 为此,只需在input元素中添加属性checked <input type="radio" name=&qu ...
- R语言数据处理利器——dplyr简介
dplyr是由Hadley Wickham主持开发和维护的一个主要针对数据框快速计算.整合的函数包,同时提供一些常用函数的高速写法以及几个开源数据库的连接.此包是plyr包的深化功能包,其名字中的字母 ...
- 深度解析Java8 – AbstractQueuedSynchronizer的实现分析(上)
本文首发在infoQ :www.infoq.com/cn/articles/jdk1.8-abstractqueuedsynchronizer 前言: Java中的FutureTask作为可异步执行任 ...
- struts2中jsp前台传值到后台action的方法(转)
在Struts2中jsp前台传值到action后台的方法 分类: java2012-02-28 13:58 2171人阅读 评论(1) 收藏 举报 actionstrutsjspgetterstrin ...
- [Leetcode][JAVA] Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 ...
- 一步一步安装hive
安装hive 1.下载hive-0.11.0.tar.gz,解压; 2.下载mysql-connector-java-5.1.29-bin.jar并放到hive/lib/下: 3.配置hive/con ...