简体   繁体   English

Flash CS5:AS3-导入瑞士法郎播放X秒钟吗?

[英]Flash CS5:AS3 - Import swf to play for X seconds?

I need to have a swf load at the beginning, but I don't want to play about the last 3 seconds of the video. 我需要在开始时加载swf,但是我不想播放视频的最后3秒钟。

Can someone help me out with a code that would basically have my swf play for "x" seconds? 有人可以帮我解决一个基本上让我的瑞士法郎播放“ x”秒的代码吗?

Heres what I Have so far.. Currently it is set up to play the swf, but subtract "x" seconds from it but for some reason it doesn't seem to work 这是到目前为止我所拥有的。.目前已设置为播放swf,但是从中减去“ x”秒,但由于某种原因,它似乎不起作用

var mySwf:MovieClip;
var reducedTotalFrames:int;

var clipLoader:Loader = new Loader();
clipLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
clipLoader.load(new URLRequest("schoolintro.swf"));

function loadComplete(e:Event):void
{
     mySwf = LoaderInfo(e.currentTarget).content as MovieClip;

     var totalFrameCount:int = mySwf.currentScene.numFrames;

     var secondsToSubtract:int = 3;

     var threeSecondFrameCount:int = (stage.frameRate * secondsToSubtract);

     reducedTotalFrames = totalFrameCount - threeSecondFrameCount;

     stage.addEventListener(Event.ENTER_FRAME, onRender);

     stage.addChild(mySwf);


}

function onRender(e:Event):void
{
     if(mySwf != null && mySwf.currentFrame >= reducedTotalFrames){
          //This is the end of the SWF with 3 seconds trimmed off. Here we can stop play
          stage.removeEventListener(Event.ENTER_FRAME, onRender);
          mySwf.stop();
          //doSomethingElse();
     }
}

I think you just need to change this line from 我认为您只需要更改此行即可

var threeSecondFrameCount:int = (stage.frameRate * secondsToSubtract);

to

var threeSecondFrameCount:int = (stage.frameRate / secondsToSubtract);

not sure is this what you want or not. 不确定这是您想要的与否。

Try some basic debugging, like placing trace statements in the code inside onRender to ensure it's being called, to ensure the mySwf reference is working correctly (for example, tracing out mySwf.currentScene.numFrames, and if its 0, you know you're not referencing your swf properly or the swf is not frame-based). 尝试一些基本的调试,例如将跟踪语句放在onRender内的代码中以确保被调用,以确保mySwf引用正常工作(例如,跟踪mySwf.currentScene.numFrames,如果其值为0,则表示您知道无法正确引用您的瑞士法郎,或者瑞士法郎不是基于帧的)。 If it the SWF is not frame-based, then you're going to have real issues controlling or even doing anything about this since all the animation/action going on inside the loaded SWF is code-based. 如果SWF不是基于帧的,则在控制甚至执行任何操作方面都会遇到实际问题,因为加载的SWF内部进行的所有动画/动作都是基于代码的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM