FPS control of loaded swf

I am working on a flash application where I download multiple swf. But the problem is that they have different frames (12/25/30). If I add 2 swf, they both play at 25fps. I found many questions about this, but I cannot get it to work (in AS3). Does anyone know why this is not working and how to get it to work?

public class MainClass extends MovieClip 
    {
        var loader:Loader = new Loader();
        var request:URLRequest;

        var mcMedia:MovieClip = new MovieClip();

        MovieClip.prototype.setFrameRate = function(frameRate:Number)
        {
            var mc:MovieClip = this;
            if (mc.tweenFaster != null)
            {
                Timer(mc.tweenFaster).stop();
            }
            mc.tweenFaster = new Timer(1000/frameRate);
            mc.tweenFaster.addEventListener(TimerEvent.TIMER, timelineFaster);
            mc.tweenFaster.start();

            function timelineFaster(event:TimerEvent = null)
            {               
                if (mc.currentFrame == mc.totalFrames)
                {
                    mc.tweenFaster.stop();
                    mc.gotoAndStop(1);
                }
                else
                {
                    trace(mc.currentFrame);
                    mc.nextFrame();
                }                           

                event.updateAfterEvent();
            }
        }

        public function MainClass() 
        {
            configureListeners();
            request = new URLRequest("data/7/7.swf");

            try 
            {
                loader.load(request);
            } 
            catch (error:Error) 
            {
                trace("Unable to load requested document.");
            }
        }

        private function configureListeners():void 
        {           
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
            loader.contentLoaderInfo.addEventListener(Event.OPEN, openHandler);
            loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }

        private function completeHandler(event:Event):void 
        {
            loader.content.scaleX = 550/event.target.width;
            loader.content.scaleY = 400/event.target.height;
            mcMedia.addChild(loader);
            mcMedia.setFrameRate(12);
            addChild(mcMedia);
        }

      

+1


a source to share


4 answers


In as3, if you just want to change the frame rate, use stage.frameRate = 12; or something else,

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Stage.html#frameRate

In AS3, while you can use prototypes, you usually don't. I would rewrite your setFrameRate function (which is badly named, shouldn't there be more. TweenFaster or matchFrameRate or whatever?)



I would make a helper function like this:

package util{

//imports

public class TweenFasterMC extends MovieClip{

   public var mc:MovieClip;

   public function matchFrameRate(frameRate:Number):void
   {
                if (tweenFaster != null)
                {
                        Timer(mc.tweenFaster).stop();
                }
                tweenFaster = new Timer(1000/frameRate);
                tweenFaster.addEventListener(TimerEvent.TIMER, timelineFaster);
                tweenFaster.start();

    }

    function timelineFaster(event:TimerEvent = null):void
    {                               
                        if (currentFrame == totalFrames)
                        {
                                tweenFaster.stop();
                                gotoAndStop(1);
                        }
                        else
                        {
                                trace(currentFrame);
                                nextFrame();
                        }                                                       

                        event.updateAfterEvent();
    }

}

      

Also, clean up your event listeners, that a strong timer event listener will cause tons of problems if you have many applications that you have applied this functionality to.

+1


a source


As far as I know, all MovieClips in one instance of a flash player (sharing the same "stage") will run at the same speed - there is no way to run two clips at different speeds. So to tune the speed, you need to resort to calling gotoAndStop () on all the clips in the loaded clip at the right time - it won't be fun.



The code along the lines displayed by quoo will only work if the loaded swf contains only 1 MovieClip (no nesting) as far as I can see.

0


a source


It seems to me that the most likely reason why this won't work is because every clip you load requires a simple, completely non-dynamic animation that loops forever. If the uploaded content is so simple, why not just tweak it to look better at 30fps? (If it's very long, a JSFL script can automate the process of adding extra frames.) Alternatively, if the content isn't that simple, then trying to change its time by calling nextFrame

from somewhere else won't give you what you want.

That being said, if you are sure this is what you want to do, but you get a 0 as a return for your currentFrame

uploaded content, are you sure this is ASF SWF? If it is not, AS3 / AS2 communication is a hairy subject that will require reading.

0


a source


This is a real problem, I cleaned the net for an answer. I have particles along the way, and I want to change the speed at which those particles follow the path dynamically, without changing the whole movie. just a movie clip.

I tried greensock but it doesn't actually work as if I need it. I would think that you can change dynamically for each mc, but not dice.

stage.frameset is for the whole movie only ... argggggggg ..... sucks ..

0


a source







All Articles