Friday, May 23, 2008

Creating subtitles for flash video using XML

Hi Folks,
This tutorial will show how to create subtitles on-the-fly from content stored in XML format. It assumes that you know how to create an FLV (Flash Video) file.

First step: Create the Flash file
First you need to create a new fla file and import the FLV file to the main stage. This is automatically wrapped in a FLVPlayback component. Give this the instance name of video1. A dynamic text field also needs to be created for displaying the subtitles. Assign this text field the instance name txt_output.

About cuepoints
Adobe describes a cuepoint as ‘a point at which the video player dispatches a cuePoint event while an FLV file plays’.

We will create a cuepoint for every point in the video that we want to display a subtitle. Cuepoints can be defined directly on the FLVPlayback Component’s Parameter Pane, located on the Component Inspector or the Properties pane. However, we will go a step further and create the cuepoints dynamically using Actionscript.

Each cuepoint requires; a name, the time (in seconds) when it will be displayed, and the text that will be displayed. This information will be stored in an XML file called cuepoints.xml and will follow this structure;



Parsing cuepoints.XML
The first thing to do is to get the subtitle information for each cuepoint from cuepoints.xml. We will use a Class developed by Antonio De Donitas called
XModel. This is a very useful class that makes parsing XML files easier. The purpose of the XModel class is to convert XML data into an ActionScript object whose properties are named after the elements and attributes in the XML data.
The XModel class improves upon the built-in functionality of AS2 by:
  • Reducing the amount of code required to access the XML data.
  • Making your application-specific code much more readable and, therefore, much easier to extend and maintain.

Here’s a snippet of the code;

var theContent:XModel = new XModel();
var listener = new Object();
theContent.addEventListener("onModelledObject", listener);
theContent.load("xml/cuepoints.xml");


The use of the XModel class follows the same event-driven approach that is broadly used in Flash applications:

  • Cuepoints.xml is loaded using an XModel instance called theContent.
  • A listener object called listener has been created and registered so that it listens for an event called onModelledObject, which is triggered by theContent.


Detail of onModelledObject
onModelledObject stores the details of each subtitle in an array for later retrieval. XModel makes the parsing code a lot more meaningful and easier to follow since it allows you to access the xml content by referencing the actual node names. A function called createCuepoint() is also invoked for every iteration of arr_cue_points. Here is what this function looks like;

function createCuepoint(cTitle:String, cTime:String):Void{
var cuePt:Object = new Object(); //create cue point object
cuePt.time = Number(cTime);
cuePt.name = cTitle;
cuePt.type = "actionscript";
video1.addASCuePoint(cuePt); //add AS cue point
}

Code for createCuepoint()
The final line in this function adds the cuepoint to a FLVPlayback instance called video1.

Triggering cuepoints at runtime
Now we need to listen for cuePoint events that occur while the FLV file plays.
A listener object called listenerObject is created and registered to listen for the occurrence of cuePoint events. A cuepoint event is dispatched when the amount of lapsed time is the same as the time property for a cuepoint. Here’s what it looks like;

//populate cuepoints...
var lastCue:Number;
var listenerObject:Object = new Object();
listenerObject.cuePoint = function(eventObject:Object):Void {
var str_name = eventObject.info.name.toString();
_root.txt_output.text = arr_cue_points[str_name].cueText;
}

Handling cuePoint events
Every time a cuepoint is active, the subtitle text for that cuepoint (which is stored in the array we created earlier) is written to a dynamic textfield called txt_output.

Don't forget to add:video1.addEventListener("cuePoint", listenerObject); in your code.



If you require the source files, feel free to ask. :)

Monday, May 12, 2008

Flash Hacks - Flash Performance

Hi Gang,
I have found some very important stuff related to Flash performance. Refer to the following link:
http://www.actionscript.org/resources/articles/579/1/Flash-Hacks/Page1.html

This post is similar to the one posted by Shaurya, with additional information. It’s a bit old and caters to flash 6, 7, and 8, but the info it gives is still relevant, useful and pretty long.

Enjoy !!!

Thursday, March 6, 2008

about flash performance

Hey People!
In doing SRM06 we faced a major hurdle about flash performance – flash kept crashing
In investigating all that we got to learn a lot of under the hood stuff about the flash player and the flash compiler.Much of it would require a lot of space to share…But, there was one very interesting resource that I dug up, rummaging thru my favs. Folder… hehe .
http://oddhammer.com/actionscriptperformance/
The site is very informative about flash performance issues, has some tests calibrating various operations to milliseconds too!Also there is a wealth of other stuff here – including tutorials on Unicode characters in flash.
It’s a bit old and caters to flash 6, 7, and 8, but the info it gives is still relevant and useful
Enjoy!

:) :) :)

Shaurya Agarwal

Thursday, January 10, 2008

ActionScript 3.0 compatibility with previous versions

Some points to be keep in mind while working with flash previous version (1.0 & 2.0)

.......

Compatibility with previous versions

As always, Flash Player provides full backward compatibility with previously published content. Any content that ran in previous versions of Flash Player runs in Flash Player 9. The introduction of ActionScript 3.0 in Flash Player 9, however, does present some challenges for interoperability between old and new content running in Flash Player 9. The compatibility issues include the following:


A single SWF file cannot combine ActionScript 1.0 or 2.0 code with ActionScript 3.0 code.

ActionScript 3.0 code can load a SWF file written in ActionScript 1.0 or 2.0, but it cannot access the SWF file's variables and functions.

SWF files written in ActionScript 1.0 or 2.0 cannot load SWF files written in ActionScript 3.0. This means that SWF files authored in Flash 8 or Flex Builder 1.5 or earlier versions cannot load ActionScript 3.0 SWF files.

The only exception to this rule is that an ActionScript 2.0 SWF file can replace itself with an ActionScript 3.0 SWF file, as long as the ActionScript 2.0 SWF file hasn't previously loaded anything into any of its levels. An ActionScript 2.0 SWF file can do this through a call to loadMovieNum(), passing a value of 0 to the level parameter.

In general, SWF files written in ActionScript 1.0 or 2.0 must be migrated if they are to work together with SWF files written in ActionScript 3.0. For example, say you created a media player using ActionScript 2.0. The media player loads various content that was also created using ActionScript 2.0. You cannot create new content in ActionScript 3.0 and load it in the media player. You must migrate the video player to ActionScript 3.0.

If, however, you create a media player in ActionScript 3.0, that media player can perform simple loads of your ActionScript 2.0 content.

Wednesday, November 28, 2007

Making Games from Scratch

I found something very much interesting on site called as “Scratch” its a tool which allow user to create your own interactive stories, animations, games, music, and art and this is all done just by dragging “sprites” on the stage and by assigning value to the variables ! ..So I download the tool and checked out the feature, I really found it very much brainstorming tool for kids its good ….but….. “Ye “but” he tho problem hai” I was thinking we can do much more then this using flash, flex ,director or any other technology.

Just a thought

We can build an engine which will allow users to create game, quiz, assessment, simulations, e-Books etc, this sounds big and complex but nothing seems impossible.

Check this out

http://kidconfidence.com/blogs/2007/10/07/creating-a-video-game-from-scratch-a-fun-way-to-teach-kids-about-computers/

eLearning Technology: Flash Quiz Tools

I found some useful information related to eLearning tools on the net. Thought it would be worth, if I shared it with you all. Following is the info which I found.
---------------------------------------------------------------------------------
A client wanted to create online quizzes that would live inside of a larger site. They didn't really need tracking of user responses, instead they wanted them to be fun. I suggested a couple of tools, but then wondered if I had given them the best list of tools.


So, the eLearningGuild research again to the rescue... Here's guild member satisfaction ratings for tools in the test / quiz category. Note: there are additional rating items such as would use again, vendor responsiveness, etc.


Note - the empty column now contains links to more information on the tools. So I could quickly gather specific data on the product. Unfortunately, it didn't tell me how they produced output and the desire was for self-contained Flash. But, I could quickly link to the sites to find out more and finally recommended that they should look at:

Articulate Quizmaker allows you to easily create Flash-based quizzes, surveys, and assessments. And, Quizmaker allows you to track your results with your standards based Learning Management System as Quizmaker output is SCORM and AICC compliant.

Adobe Captivate is the easiest way to create professional-quality, interactive simulations and software demonstrations in Adobe's Flash format. Without any programming or multimedia skills, users can automatically record onscreen actions, including editable mouse movements, text captions, and scored click boxes. Add e-learning interactions like data-entry fields and customizable quizzes.

Respondus StudyMate is a Windows authoring tool that lets you create numerous Flash-based activities and games using four simple templates. StudyMate provides an authoring environment that requires no experience with Flash programming, game design, or HTML. Questions and items can also be imported from MS Word, IMS QTI, Respondus, rich-text, and other formats. This makes it possible to create interesting, interactive activities from existing content. Other features include an Equation Editor, a spell checker, the ability to include image files and web links, and question/answer randomization. The Flash activities that can be created with StudyMate include: Fact Cards, Fact Cards Plus, Flash Cards, Fill In the Blank, Pick A Letter, Matching, Glossary, Crosswords, Quiz, and Challenge. It is also possible to generate three activities that can be used with iPods, PSP players and other portable devices.

OnDemand Presenter provides the ability to develop robust multi media content allowing you to easily incorporate both conceptual and transactional information into interactive presentations. Creates interactive questions and tests using 14 different question and survey types.

Rapid Intake Flashform Rapid eLearning Studio creates interactive Flash-based AICC or SCORM-conformant e-learning courseware. Quickly create Flash-based e-learning courses, quizzes, and tests. Add an integrated glossary - Add external audio, video, and images into the course content Flashform is customizeable and extensible by any knowledgeable Flash developer.
-------------------------------------------------------------------------------------------------------------