as3swf icon indicating copy to clipboard operation
as3swf copied to clipboard

求大神指教如何把一段影片剪辑写入到swf文件中

Open chinesedeveloper opened this issue 10 years ago • 3 comments

import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.events.Event; import com.codeazur.as3swf.SWF; import flash.net.URLRequest; import flash.filesystem.File; import flash.utils.ByteArray; import flash.filesystem.FileStream; import flash.filesystem.FileMode; import com.codeazur.as3swf.tags.TagFileAttributes; import com.codeazur.as3swf.tags.TagEnd; import com.codeazur.as3swf.tags.TagDefineSprite; import com.codeazur.as3swf.tags.TagShowFrame; import com.codeazur.as3swf.data.SWFMatrix; import com.codeazur.as3swf.tags.TagPlaceObject;

var urlLoader:URLLoader = new URLLoader(); urlLoader.load(new URLRequest(File.desktopDirectory.resolvePath("a.swf").nativePath)); urlLoader.dataFormat = URLLoaderDataFormat.BINARY; urlLoader.addEventListener(Event.COMPLETE,onCmp);

function onCmp(e:Event):void{ var swf:SWF = new SWF(e.currentTarget.data); var tagSpr:TagDefineSprite; for(var i:int =0;i<swf.tags.length;i++){ if(swf.tags[i] is TagDefineSprite){ tagSpr = swf.tags[i] as TagDefineSprite; } }

var newswf:SWF = new SWF(); newswf.tags.push(new TagFileAttributes); newswf.tags.push(tagSpr)

var tagPlaceObj:TagPlaceObject = new TagPlaceObject(); tagPlaceObj.hasCharacter = true; tagPlaceObj.characterId = 2; tagPlaceObj.depth = 99; tagPlaceObj.hasMatrix = true; tagPlaceObj.matrix = new SWFMatrix(); newswf.tags.push(tagPlaceObj); newswf.tags.push(new TagShowFrame); newswf.tags.push(new TagEnd);

var ba:ByteArray = new ByteArray(); newswf.publish(ba);

var fileStream:FileStream = new FileStream(); fileStream.open(File.desktopDirectory.resolvePath("b.swf"),FileMode.WRITE); fileStream.writeBytes(ba); fileStream.close(); fileStream = null; }

问题:newswf.tags.push(tagSpr) 这个句子无法创建成功,can not create a sprite to a swf file successfully 劳资找遍百度、谷歌、雅虎都没找到成功new DefineSprite()的方法,尼玛!万分无奈之下求助于楼主。希望楼主大神指教下,楼主好人,感谢楼主!

chinesedeveloper avatar Oct 14 '14 09:10 chinesedeveloper

возможно, проблема в том, что tagSpr равен null, когда ты его добавляешь в newswf.tags. убедись, что TagDefineSprite действительно присутствует в a.swf :earth_asia:

@claus ты же в Бразилии? поддержи тренд, отвечай на португальском.

makc avatar Oct 14 '14 09:10 makc

~~Ausserdem ist onCmp eine asynchrone Funktion, der Rest aber nicht. tagSpr wird deshalb erst später instanziiert, mit was auch immer, und ist bis dahin nicht definiert.~~ OK das war Blödsinn. Habe eine geschweifte Klammer übersehen. @makc's Antwort ist richtig.

@makc Nee ich bin grade in Deutschland. Fliege zurück nach Brasilien in zwei Wochen.

claus avatar Oct 14 '14 09:10 claus

Eu cred, ca tu ai uitat sa-l verifice valoarea al tagSpr. In primul rind astepta executare metodului onCmp si numai dupa aceea construieste noul swf :earth_asia:

profelis avatar Oct 14 '14 11:10 profelis