Showing posts with label tag. Show all posts
Showing posts with label tag. Show all posts

Thursday, April 12, 2007

Flash object fails to call Javascript function

The most popular way to show video in web pages today is to play the video files inside flash players that are embedded inside the html page. Like everyone else we did it too and it works just fine.

A new feature that we added to our site is the ability to embed our flash player into any blog or site page, and for this purpose we also added a feature that sends information from the flash player to our server each time someone plays one of our videos somewhere out there. That way we can count how many views our videos get even outside the site.


When we added this view-counter feature we could not get it to work. The flash player did not reach the server page even though we wrote the calling code properly.


After looking at some professional blogs and sites we found out the problem: we use the name "5minPlayer" as our player tag name, and the Object tag that holds the flash player should not begin with a number...


There are other limitations to this object tag, and also many things you should know if you are going to use flash on your page, especially if you are implementing extensive interaction between flash and the html page. A great page on this issue can be found here.

Thursday, March 15, 2007

Parsing tags input using Split function

User input validation is one of the more complex issues in developing a solid data-entry form. Input validation is the basis of application security, database integrity, application stability and more.

Today i encountered an input validation issue regarding the input that users enter as "tags", the popular new type of information used in many User Generated Content (UGC) sites.

When i used the function Split from the String class to parse the tags into an array of strings i found out that if the user entered multiple space characters (eg. "tag1 tag2 tag3") each space from the second one will result in an empty cell in the tags array. Splitting these sample tags will result in this array:
array[0]: "tag1"
array[1]: "tag2"
array[2]: ""
array[3]: ""
array[4]: ""
array[5]: "tag3"

In order to avoid entering blank tags in the database i wrote a simple function that prepares a clean array of tags from the raw tags string. Here it is:
(Besides removing empty cells this function also convert commas to blanks and lowers the case for all tags. This avoids multiple-word tags and case differences, as our project demands)


private string[] PrepareTags(string tags)
{
char[] delim = { ' ' };
//Replace comma with blank
tags = tags.Replace(",", " ");
//Split to array with blank delimiter
string[] tagsArray = tags.Split(delim);
ArrayList tagsList = new ArrayList();
//Eliminate empty cells
string[] preparedTags;
for (int i = 0; i < tagsArray.Length; i++)
{
if (tagsArray[i].Trim().Length > 0)
//Make all tags lowercase
tagsList.Add((string)tagsArray[i].ToLower());
}
preparedTags = new string[tagsList.Count];
tagsList.CopyTo(preparedTags);
return preparedTags;
}


If you find this function useful please comment and tell me.