我一直在搜索网页,我发现的所有代码都是播放具有时间轴的外部swf文件。我正在尝试加载的文件没有时间轴。我正在为这个项目使用Flixel框架,我想要播放的文件也是在Flixel中制作的(没有源文件只是swf文件)。Flixel - 如何加载和播放嵌入式swf文件
我拥有的大部分代码都来自我在Flixel论坛上发现的一个过场动画模板。以下是我迄今为止:
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 [email protected] to flash.display.MovieClip.
,所有我想做的是播放SWF文件的一组帧计数,然后移动到下一个状态。
有关如何做到这一点的任何想法?
我试过了,我得到这个错误:无法访问空对象引用的属性或方法。在DirtPileLogo()。 – WAC0020 2011-03-29 12:00:01
@ WAC0020你在游戏中使用预加载器吗? – 2011-03-29 17:28:51