我一直在网上搜索,我找到的所有代码都是为了播放有时间线的外部swf文件。我尝试加载的文件没有时间线。我在这个项目中使用了Flixel框架,我想播放的文件也是用Flixel制作的(不要只有swf文件的源文件)。
我拥有的大部分代码都来自于我在Flixel论坛上找到的一个cutscene模板。这是我到目前为止所知道的:
package
{
import org.flixel.FlxState;
import org.flixel.FlxG;
import flash.display.MovieClip;
import flash.media.SoundMixer;
import flash.events.Event;
public class SponsorsState extends FlxState
{
//Embed the cutscene swf relative to the root of the Flixel project here
[Embed(source='assets/DirtPileLogo.swf', mimeType='application/octet-stream')] private var SwfClass:Class;
//This is the MovieClip container for your cutscene
private var movie:MovieClip;
//This is the length of the cutscene in frames
private var length:Number;
override public function create():void
{
movie = new SwfClass();
//Set your zoom factor of the FlxGame here (default is 2)
var zoomFactor:int = 2;
movie.scaleX = 1.0/zoomFactor;
movie.scaleY = 1.0 / zoomFactor;
//Add the MovieClip container to the FlxState
addChildAt(movie, 0);
//Set the length of the cutscene here (frames)
length = 100;
//Adds a listener to the cutscene to call next() after each frame.
movie.addEventListener(Event.EXIT_FRAME, next);
}
private function next(e:Event):void
{
//After each frame, length decreases by one
length--;
//Length is 0 at the end of the movie
if (length <= 0)
{
//Removes the listener
movie.removeEventListener(Event.EXIT_FRAME, next);
//Stops all overlaying sounds before state switch
SoundMixer.stopAll();
//Enter the next FlxState to switch to
FlxG.state = new PlayState();
}
}
}}
当我运行这个命令时,我得到了这个错误:Type Coercion failed: cannot convert SponsorsState_SwfClass@fb5161 to flash.display.MovieClip.,我想要做的就是播放设定帧数的swf文件,然后进入下一个状态。
你有什么建议吗?
发布于 2011-03-29 00:01:44
尝试替换以下内容:
[Embed(source='assets/DirtPileLogo.swf', mimeType='application/octet-stream')]
private var SwfClass:Class;
//This is the MovieClip container for your cutscene
private var movie:MovieClip;转到
//Mark your symbol for export and name it => MyExportedSymbol
[Embed(source='assets/DirtPileLogo.swf', symbol = "MyExportedSymbol")]
private var SwfSymbol:Class;
//Make sure that MyExportedSymbol base class is MovieClip
private var movie:MovieClip = new SwfSymbol;基本上,您将您的符号标记为导出,给它一个名称并在嵌入代码中使用它。您将仅嵌入该符号。
发布于 2011-03-29 00:06:28
您在嵌入上错误地设置了mimeType。卸下mimeType,它应该可以正常工作。有关更多信息,请参阅embedding assets上的文档。
发布于 2011-09-04 22:10:52
我相信您正在寻找的解决方案是使用Loader类。
[Embed (source = "assets/DirtPileLogo.swf", mimeType = "application/octet-stream")]
private var content:Class;
private var loader:Loader;
public function Main():void
{
var data:ByteArray = new content();
loader = new Loader();
addChild( loader );
loader.loadBytes( data, new LoaderContext(false, new ApplicationDomain() ) );
// ... add listener to loader if necessary, etc...
}https://stackoverflow.com/questions/5461500
复制相似问题