Actionscript 3 Flixel-如何加载和播放嵌入式swf文件
我一直在网上搜索,我找到的所有代码都是播放有时间轴的外部swf文件。我尝试加载的文件没有时间线。我在这个项目中使用了Flixel框架,我想播放的文件也是用Flixel制作的(没有源文件,只有swf文件) 我拥有的大部分代码都来自于我在Flixel论坛上找到的一个cutscene模板。以下是我到目前为止的情况:Actionscript 3 Flixel-如何加载和播放嵌入式swf文件,actionscript-3,flash,embedding,playback,Actionscript 3,Flash,Embedding,Playback,我一直在网上搜索,我找到的所有代码都是播放有时间轴的外部swf文件。我尝试加载的文件没有时间线。我在这个项目中使用了Flixel框架,我想播放的文件也是用Flixel制作的(没有源文件,只有swf文件) 我拥有的大部分代码都来自于我在Flixel论坛上找到的一个cutscene模板。以下是我到目前为止的情况: package { import org.flixel.FlxState; import org.flixel.FlxG; import flash.display.MovieClip
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();
}
}
}
包
{
导入org.flixel.FlxState;
导入org.flixel.FlxG;
导入flash.display.MovieClip;
导入flash.media.SoundMixer;
导入flash.events.Event;
公共类赞助商状态扩展FlxState
{
//在此嵌入相对于Flixel项目根的cutscene swf
[Embed(source='assets/DirtPileLogo.swf',mimeType='application/octet stream')]私有变量SwfClass:Class;
//这是用于剪切场景的MovieClip容器
私人电影:MovieClip;
//这是以帧为单位的剪切场景的长度
私有变量长度:数字;
重写公共函数create():void
{
电影=新的SwfClass();
//在此处设置FlxGame的缩放因子(默认值为2)
变量zoomFactor:int=2;
movie.scaleX=1.0/zoomFactor;
movie.scaleY=1.0/zoomFactor;
//将MovieClip容器添加到FlxState
addChildAt(电影,0);
//在此处设置剪切场景的长度(帧)
长度=100;
//将侦听器添加到cutscene,以便在每帧后调用next()。
movie.addEventListener(Event.EXIT_FRAME,next);
}
下一个私有函数(e:事件):无效
{
//每帧后,长度减少1
长度--;
//电影结尾处的长度为0
如果(长度尝试更换以下部件:
[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;
进入
基本上,您将符号标记为导出,给它一个名称并在嵌入代码中使用它。您将只嵌入该符号。您在嵌入上设置的mimeType不正确。删除mimeType,它应该可以正常工作。有关详细信息,请参阅上的文档。我相信您正在寻找的解决方案是使用Loader cla党卫军
[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...
}
我试过了,但得到了一个错误:无法访问空对象引用的属性或方法。在DirtPileLogo()。@wac020,您在游戏中使用了预加载程序吗?
[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...
}