Thursday, January 28, 2010

IE7 javascript error in for each loops

One of the reasons I like Flash is the fact that one piece of code will work on every browser. But not so with javascript. Case in point:

If you have an array (langArray) in javascript and want to loop through it the common way is this:

for each(var item in langArray){
...
}

but this causes IE 7 to choke. Instead you have to use the more verbose:

for(var item=0;item var item = langArray[i];
...
}

Thursday, January 21, 2010

Flash elements disappear in full screen mode

I was surprised to find that a button and a dropdown list disappeared when I went full screen on a Flash app. Turns out that if you use an FLVPlayerback component it forces everything else on screen to disappear if you go fullscreen. Nice feature unless you don't want that to happen.

To fix it:

myFlvPlayback.fullScreenTakeOver = false;


Thanks Adobe forums :-)

Thursday, January 7, 2010

Working with AS3 Video cuepoints

I have been working with cuePoints in flash video and so far have been unable to add actionscript cuePoints and then seek to them. (Update: see solution below)
  • Encode a video: "myVideo.flv" without embedded cuePoints
  • Attach the video to a FLV playback component "my_FLVPlybk"
  • Add cuepoints like this: my_FLVPlybk.addASCuePoint(15, "Cue1");
  • Set up an event Listener to see if the cuepoints are there:
my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener);

function cp_listener(eventObject:MetadataEvent):void {
trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
trace("Cue point name is: " + eventObject.info.name);
trace("Cue point type is: " + eventObject.info.type);
}

When you run the app, it all works expected. Once the cuepoints are reached it traces out each point. However when you try to go to the cuepoint using this method:

my_FLVPlybk.seekToNavCuePoint("Cue1");

It fails with this error:

VideoError: 1003: Invalid seek
at fl.video::FLVPlayback/seekToNavCuePoint()

Now, this last bit of code works fine if you embed navigation cuepoints in the video itself -- using Adobe Media Encoder (FLV only -- F4V seems not to support cuepoints--at least not well), but according to Adobe it should be possible to add the cuepoints and reference them through actionscript only. In this particular case its not a problem for me since its easier to add the cuepoints to the encoded video, but if anyone has come up with a solution, please post it!


***************************

Update: I found the solution on another forum (http://bit.ly/8EdgdN):

The answer is to locate the cuePoint using findCuePoint() -- which returns an associative array of the point -- and then get the value of "time". At this point you can just do a seek. The final code would be like this:

my_FLVPlybk.seek(my_FLVPlybk.findCuePoint("Cue4", CuePointType.ACTIONSCRIPT)["time"]);