views:

1378

answers:

5

I'm working on a flash app where I load multiple swf's. But the problem is that they have different framerates (12/25/30). If I add 2 swf's they both play at 25fps. I found numerous topic about this but I can't get it to work (in AS3). Does anyone know why it doesn't work and how to make it working?

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);
        }
A: 

In as3, if you're just looking to change the framerate, use stage.frameRate = 12; or whatever;

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

In AS3, while you can use prototypes, you generally don't. I'd rewrite your setFrameRate function (which is badly named, shouldn't it be more.. tweenFaster, or matchFrameRate or something?)

I'd 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 strong timer event listener will cause a lot of problems if you have a lot of mc's your applying this functionality to.

quoo
I know of stage.frameRate but I can't use because I have 2 movieclips simulatneously, 1 orginal fps is 25 and the other one is 12. When i use the stage.frameRate both clips will run at 12 or 25.Also this function doesn't change the playback of the movieclip. Still at the same framerate as the root swf (25fps). Also trace(currentFrame); only prints zeros
PoweRoy
I don't think this works for nested MovieClips or does it?
Simon Groenewolt
Why wouldn't it? You'd just need ever clip whose speed you wanted to control to extend this though.
quoo
A: 

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

Code along the lines that quoo is showing will only work if the loaded swf contains just 1 MovieClip (no nesting) as far as I can see.

Simon Groenewolt
I have a much larger flash program. I created a much smaller app with only the playback problem."So to adjust the speed you have to resort to calling gotoAndStop() on all MovieClips in the loaded clip"This is not working for nested clips because trace(currentFrame); only prints zeros
PoweRoy
In that case you probably have some nested movieclips in your swfs - the outer movieclip only has a single frame, and one of the inner movieclips contains the actual animation. If you don't have the original fla files it will be very hard to resolve your issue.
Simon Groenewolt
... this is assuming you have flash files with animations done on the timeline, if the animation is scripted these solutions won't help at all.
Simon Groenewolt
My code was intended to be a base class for any movieclip whose speed you wanted to control.
quoo
A: 

It seems to me that the most likely reason why this wouldn't work is that it requires every clip you load to be a simple, completely non-dynamic animation that loops for ever. If the loaded content is that simple, why not just adjust it to look better at 30fps? (If it's extremely long, a JSFL script could automate the process of adding extra frames.) Alternately, if the content isn't that simple, then attempting to change its timing by calling nextFrame from elsewhere is not going to give you what you want.

With all that said, if you're sure this is what you want to do but you're getting 0 as a return for currentFrame in your loaded content, are you sure they are AS3 SWFs? If they aren't, AS3/AS2 interoperation is a hairy subject that will warrant reading up on.

fenomas
A: 

Thanks for support all! The swf's I want to play are from 3rd parties, I don't have access to the code/animations. Due this problem I don't know if the swf are plain simple animations or if they have scripted events (let alone wat version of action script).

PoweRoy
A: 

This is a real hassle, I've been scouring the net for an answer. I have particles following a path, and I want to change the speed that these particles follow the path dynamically, without changing the whole movie. just the particles movie clip.

I've tried greensock, but, that doesn't really work like i need.. i'd think there would be something that you can change dynamically for each mc, but, no dice.

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

george.