简体   繁体   中英

Flash CS5: AS3 - remove ending of swf file?

I made a video in flash which somehow got corrupted, so the fla is no longer usable. Instead of remaking the video, I would like to just snip off the end of the .swf that I published and then probably just play a second .swf immediately after to end it (with replay buttons and a link to a particular website)

My question is: Is it possible for me to cut the .swf by about 3 seconds at the end?

Assuming this is a frame-based animation or swf, when you load the swf you can get the total number of frames using MovieClip(mySwf).currentScene.numFrames. So the way you would shave off 3 seconds would be to work out how many frames 3 seconds would be based on the current framerate, then inside an ENTER_FRAME callback check the currentFrame and act when you detect it is equal to (totalFrames less 3 seconds worth of frames). The code looks like:

* Note: Code edited, see comments *

var mySwf:MovieClip;
var reducedTotalFrames:int;

var clipLoader:Loader = new Loader();
clipLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
clipLoader.load(new URLRequest("http://www.mysite.com/mySwf.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);

     mySwf.gotoAndPlay(1);
}

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

Code is off the top of my head but at the very least, if it doesn't already work as-is, you should have a solid enough understanding of the concept to make it work or implement it as you see fit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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