Which is more efficient, embedding FLV or compiling FLV to SWF and loading it dynamically?

I recently took on the rather daunting task of creating an interactive music video for the popular Ghost Whisperer show. I was introduced at the end of the project and came across a huge authoring file (about 5000+ frames). The previous programmer (who did everything in AS2) essentially brought in two and a half minutes FLV during the main timeline and in certain frames added clips for interactivity with basic mouse click functions that would make those clips play other clips with some flash elements and some video elements.

(the final version I created can be viewed here http://www.gwghostmagic.com );

Being a neat freak, I decided to rebuild the whole thing in AS3, drop the timeline entirely, and rather load my elements at runtime so that instead of 5000 frames I have one frame and add an event to trigger actions. ENTER_FRAME to trigger interactivity when the loaded .swf reaches certain frames. From a programmer's point of view, this made things much clearer and easier to manipulate certain actions. The problem was, it was being handled like shit.

Versions over 5000 frames loaded faster and ran smoother than my AS3 version. This brings me to the question, when is it better to insert and escape from the timeline than to escape from an event listener? Is flash better suited for timeline functionality?

Initially, I decided to create and disable streaming .flv, but syncing to .flv was not possible because .flv was running at 23.975 fps, while my flash movie was running at 24 fps. Alas, I was forced to compile the .swf with the embedded flv. This .swf was then loaded into my main .swf containing all the functions and additional clips that will play according to the loaded position of the .swf frame.

One thing I noticed is that Event.ENTER_FRAME seems to slow down the whole damn application because it has to skip a 200 line of code list of if commands in every frame. If this were all injected, I might only need to insert a keyframe where the interactive clip will be instantiated and then immediately know what to do, rather than looping through the if else statements.

Have I messed up trying to make things nice and neat? Is it better to flash? Should I be looking for another career? Any input is appreciated.

+2


source to share


2 answers


I think that when the event is fired, each frame, as opposed to only triggering actions, sometimes accounts for the performance difference. Hopefully, you could minimize the amount of code and conventions that get executed in the event handler.

Here's an idea I haven't tested:



var dispatch:Object = {
  f1:   function () {textBubble.text = "This is Rush Hour 2";},
  f61:  function () {textBubble.text = "";},
  f111: function () {textBubble.text = "This scene has 50 takes; "
                     +"Jackie Chan said \"Square Madison\" each time.";},
  f171: function () {textBubble.text = "";}
};
addEventListener(Event.ENTER_FRAME, function (e:event) {
  if (dispatch["f"+e.target.currentFrame] is Function) {
        dispatch["f"+e.target.currentFrame]();
  }
});

      

This uses Object as an associative array as described in the real docs.

+1


source


Chances are you're right - running 200+ lines of code on every frame slows you down. Instead of a huge list of instructions, split up your frame functions and call only the ones you need - this is an extension of the dlamblin idea - that way you use the least amount of code needed for each frame:



function doThisOnFrame20():void
{
    //do stuff...
}

function doThisOnFrame50():void
{
    //do stuff...
}

var frameFunctions:Array = new Array();
frameFunctions[20] = doThisOnFrame20;
frameFunctions[50] = doThisOnFrame50;

function enterFrameListener(event:Event):void
{
    if(frameFunctions[swfWithFLV.currentFrame] is Function)
    {
        frameFunctions[swfWithFLV.currentFrame]();
    }
}

addEventListener(Event.ENTER_FRAME,enterFrameListener);

      

+1


source







All Articles