【发布时间】:2011-03-28 15:42:11
【问题描述】:
我一直在网上搜索,我发现的所有代码都是播放具有时间线的外部 swf 文件。我尝试加载的文件没有时间线。我正在为这个项目使用 Flixel 框架,我想播放的文件也是在 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 SponsorsState_SwfClass@fb5161 to flash.display.MovieClip.,我要做的就是播放 swf 文件以设置帧数,然后进入下一个状态。
关于如何做到这一点的任何想法?
【问题讨论】:
标签: actionscript-3 flash embedding playback