开发者

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

开发者 https://www.devze.com 2023-02-24 05:01 出处:网络
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.

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.

Can someone help me out with a code that would basically have my swf play for "x" seconds?

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

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);

     reducedTo开发者_StackOverflow社区talFrames = 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();
     }
}


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). 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号