Flash Player stops animating when out of viewport

后端 未结 3 1291
灰色年华
灰色年华 2021-01-26 20:08

I have several flash movies on a site. They all loop through an animation which lasts for approximately 15 seconds (but this is not set in stone). They all begin to play at the

3条回答
  •  别那么骄傲
    2021-01-26 20:31

    If it is very important that each SWF progresses simultaneously, I would control it by JavaScript.

    Assuming each SWF file is a simple MovieClip, something like this is how I would go about it:

    Set the Document Class of each FLA file to this:

    package {
        import flash.display.MovieClip;
        import flash.external.ExternalInterface;
    
        public class ExternalInterfaceControlledMC extends MovieClip {
    
            public function ExternalInterfaceControlledMC() {
                this.stop();
                if (ExternalInterface.available) {
                    try {
                        ExternalInterface.addCallback("setFrame", jsSetFrame);
                    } catch (error:Error) {
                        trace("An Error occurred:", error.message);
                    }
                } else {
                    trace("ExternalInterface is not available");
                }
            }
    
            private function jsSetFrame(value:String):void {
                var frameNumber = int(value) % this.totalFrames;
                this.gotoAndStop(frameNumber);
            }
        }
    }
    

    In the JavaScript, you would add a reference of each instance of the SWFs into an array, then use a timer to tell each SWF to progress to a frame number.

    var swfElements; //Array
    var currFrame = 1;
    
    function onPageLoad() {
        //Init timer
        setInterval("progressFrame", 1000 / 30); //30 fps
    }
    
    function progressFrame() {
        for (var i = 0; i < swfElements.length; i++) {
            swfElements[i].setFrame(currFrame);
        }
        currFrame++;
    }
    

    Please beware that nothing about this code is tested and is only meant to be used to illustrate my train of thought.

提交回复
热议问题