JavaScript – Flash Communication

August 29, 2009 at 4:28 am | Posted in Flash, Java Script | Leave a comment
Tags:

I used to work with flash all the times, in fact we used it in almost every project through college. You can do amazing things with flash very easily and honestly I love action script[:D].
Whenever you work with flash you will find yourself need to make flash communicate with other applications.
In action script you can communicate with a host application (in my case the Browser)
through External Interface.

To do that you to write a little JavaScript Code:

First you need to get the name of the flash movie and as usual this name differs along with the browser you are using so here is a method that I found here to get you the name of the flash movie whatever the browser is:

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
             return window.document[movieName];
        }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
                if (document.embeds && document.embeds[movieName])
                    return document.embeds[movieName];
            }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
            {
                return document.getElementById(movieName);
            }
        }

// Now Call the function on your flash movie.

      function SendDataToFlashMovie(data) {
       var flashMovie = getFlashMovieObject("myFlashMovie");
       flashMovie.JStoAS(data);}

then you have to write alittel Action Script code:
Now you have to register a callback method to respond to your method call from javascript.
import flash.external.ExternalInterface;
ExternalInterface.addCallback("JStoAS", getDataFromJavaScript);
function getDataFromJavaScript(data:String):void {
// Dod whatever you want with data here
}

and that's how it's done [;)]

Beckham

Print support for Facebox and lightbox v1.0

June 9, 2009 at 6:07 pm | Posted in Java Script, Tips & Tricks | Leave a comment
Tags:

Hey, Its been a long time :) i was pretty busy in some work :( along with preparing to come back to Egypt for a small vacation isA .

Anyway, you all know  facebox and Lightbox. I wanted to allow the user to print the content of the facebox and lightbox and sadly this wasn’t available in facebox and lightbox v1.0 but it’s available in lightbox v2.0 but sadly i did some modification to my lightbox v1.0 file and i really was to lazy to redo it in lightbox v2.0 :) .
anyway attached is the facebox and lightbox v1.0 with print support.

the final output will be like that

facebox

lightbox

Beckham

Why go Facebook when you can Outlook

December 16, 2008 at 11:32 am | Posted in C#, Tips & Tricks, VSTO | Leave a comment
Tags:

Facebook to outlook

First, Facebook as a very successful social networking website already contains a lot of information that we need and that will save us a lot of work not only to get this information but to use it as well.

Second, as you already know, we all work in the morning sometimes we don’t have time to turn around and certainly don’t have time to open up a browser window and typing the Facebook URL and start logging in, it seems a lot of time which sometimes we don’t have. But yet we would like to update our personal status on Facebook. So how can I do that without wasting all that time?!

The solution is pretty easy, we all have outlook opened up since the very first second you boot up your computer at work as all work related mails comes through outlook, so why don’t we make it a bit funny and use it to update our status.

The “Facebook to Outlook” plug-in consists of two main features

  1. Friends to Contacts.
  2. Update my status.
  3. Send notification messages.

So in this post I’m gonna walkthrough how to make the first plug-in as the rest is pretty much the same. Okay, let’s go

Friends to Contacts:

As a Facebook user I have a lot of friends on Facebook and those friends already published their information and I would like to have those friends in my outlook contact list. So instead of writing down the information of my Facebook friends I just thought it will be nice to have a button that I can click and it does all the work of getting my friends information and adding them to my outlook contact list.

The bad thing is the Facebook REST services don’t allow you to get the email address of friends but I guess it’s better to just modify an existing friend and add the email instead of adding the entire contact information.

Getting friend’s information from Facebook.

To get started developing applications with the Facebook API, you first need to register your application and get an API key from Facebook which will allow you to connect to their site and download data. Their Get Started page will lead you through the process.

Now that you have an API key, you can start developing. While you can connect to Facebook and get the information manually through HTTP REST calls,

Okay we first need to get the list of facebook friends:

Next, we bind the friends list FriendSelected event, to allow the user to select his friends he wishes to add as outlook friends

Next, we add some code to the SelectedIndexChanged list to allow a user to remove a friend he already selected.

Finally, we write the code to move the facebook friends to our outlook contacts.

and the final output is


Beckham

JQuery Magic Continues –> Enable Searching and sorting in GridView at the client side.

November 16, 2008 at 12:24 pm | Posted in C#, jQuery, Tips & Tricks | Leave a comment
Tags:

I geuss you heared about JQuery, Which is an amazing JavaScript library that makes it easy to create wonderful web effects in just a few lines of code. As the website says:

“jQuery is a JavaScript library that takes this motto to heart: Writing JavaScript code should be fun. jQuery achieves this goal by taking common, repetitive, tasks, stripping out all the unnecessary markup, and leaving them short, smart and understandable.”

there are a lot of jQuery plugins such as facebox.

there is also a 2 plugins that are very cute and neat:

1- The Table Sorter Plugin

2- The table search plugin.

today i’m gonna use these plugins to allow sorting and searching for the grid view control at the client side ( No Postback)

okay, Let’s start,

first of all you need to download the jQuery, Quick Search & Table Sorter plugins.

1- Create a webpage and put in a GridView control.

2- bind your gridview to a data source. in my case i’ll use a SQL Data source, that connects to the northwind db and get some information from the [Customers] table.

gridAndDataSource

3- Now the cool part to enable the search into the grid view just add this nice piece of js code

quicksearch

just make sure to add the js files that you downloaded

refrences

4- To enable sorting is a bit tricky as the table sorter plugin is working with the standard HTML table with and tags but the grid view renders only without tag.

nothead

Okaay, how can we make the gridview renders the tag ??? We can do that by this line of code which tells the grid view to render the header row as tag.

addthead

Now to make your grid sortable at the client side just add this line

sortable

now you can search and sort your grid at the client.

finalgrid

Beckham

PLINQO: Professional LINQ to Objects

July 7, 2008 at 10:07 am | Posted in C#, LINQ | Leave a comment
Tags:

PLINQO, which stands for Professional LINQ to Objects, is a
collection of Code Smith templates that are meant to replace and extend the
LINQ to SQL designers that are included with Visual Studio 2008.

For more information about PLINQO
Check out Paul welter’s post here.

Beckham

Funny bug in ASP.NET MVC While creating a new project

June 6, 2008 at 7:36 am | Posted in ASP.Net MVC | Leave a comment
Tags:

While i was playing with ASP.NET MVC CTP3 i met this funny bug while creating a new MVC project in visual studio 2008:

1- Create a new mvc project and choose to have a test project.

2- In the project name put “-”.

3- Hit ok, The project will be created succefully, That’s great but try to build.

Apperantly the “-” has been replaced With “_” in the namespace name but the odd thing they didn’t use the right name in the test project :)

And here is the bug:

Beckham

Wrap ContinuousText Inside Label

April 11, 2008 at 8:37 am | Posted in C#, Tips & Tricks | Leave a comment
Tags:

Hey guys, I was wondering if any of you has the situation of displaying a text in a label?? sure you did. but imagine the text is tooooo long that it’s displayed in a long line, Now if you put it in the label it will be displayed in a long line too, to solve this problem there is a lot of solutions you will find if you google it. you can use a textbox and give it the look of a label and set the wrap property to true this will do the trick. but what if you have a devil user or actually ” QE Teammate “, and the text he entered is continuous as it was one word in this case it will not be wrapped. so here is a littel extension string helper method that warps the string into lines of length given as a parameter.
The idea here is to devide the string into lines and put a line break tag at the end of the line.

Ofcourse it has some drawback such as the last word of the line might be splitted.but you can put “-” or something like this at the end of the line.

Hope this is helpfu, The source code is attached.

Beckham

April 6, 2008 at 11:26 am | Posted in Tips & Tricks | Leave a comment
Tags:

Hey guys, In this post I wanted to share something very cool with
you guys, It’s Coding4Fun Developer Toolkit part of the coding4Fun Community.

A very cool toolkit that allows you to do a lot of stuff
that was very very very difficult before, you can do it now very easily.

Here is a link to some of the really cool posts that I really loved:

The first link is dedicated for the fans or Rock Band Game
everywhere and specifically  “Silver Key” folks,
Check out this.

What about foosball, it’s like the best game ever, Agree ?? check this out.

Have you ever thought that you already have a lot of friends on your facebook account and it would be nice to add these contacts to
your phone, If you did check out this one.

Okay, Now for the fans of working with two monitors, would
you like to set different desktop image to each monitor, If you do check out this one.

For ASP.Net  Fans check out this new WhoIsLooking ASP.NET
Control.

For more tutorial and samples and other very cool apps check out the Coding4Fun
Site.

Beckham

Sorting a Grid View That’s bounded to IEnumerable

March 22, 2008 at 9:39 am | Posted in ASP.Net, C#, LINQ, Tips & Tricks | Leave a comment
Tags: ,

Have you ever had a grid view that’s bounded to an IEnumerable collection? Yes.
Very well have you ever wanted to enable sorting to this grid view? Yeah, what’s the big deal?

Okay, here is the deal:-

Grid view enable automatic sorting that allows you to sort you data in the grid view without writing any code but sadly this automatic sorting is enabled only for Grid View that’s bounded to a DataSourceControl (i.e. SqlDataSource, ObjectDataSource).
You can’t do that with grid view that’s bounded to an IEnumerable collection, why?
Because actually the grid view uses the DataSourceControl to sort the data for it.

So how can I sort my gridview that’s bounded to a IEnumerable collection? You can reconstruct your collection as a table and then pass that table to a data view and sort these data using that data view sorting and then bind your grid view to the data view like that :->

This is the defenition of our customer class that will be used to fill our collection.
Notic: The serializable attribute only so we can save our list of cutomers to the ViewState.

We will need to keep track of our current sort expression and direction so we can use it later in resorting the list.

Her we fill our list of customers with some dummy data.

Change the sort direction from Ascending to Descending and vice versa.

Look at our Sorting event handler see how much code we wrote to get this done. Is this the only way to do that ?? Noooo, we can do that very easily using LINQ without creating a table or a data view.

LINQ To The Rescue:-
See all that code we wrote to create a table and fill the table with data and then creating the creating the data view, well we don’t need all of that.
We will use the Order by extension method to sort our IEnumerable collection.
ex: -

Well that’s great and everything but dude you hard coded the sort expression “customer.Id” what will I do if the user clicks on the Name column? Well you can continue hard coding and write an order by statement for each column you have and select the appropriate statement using switch case based on the user’s selections.
Dude that’s horrible I don’t like hard coding, Is there anyway else like passing the property name as a variable? Well, No you can’t pass the property name as a variable but yes there is another way,  You can use reflection to get the property name dynamically ;)

Here is our Sorting event handler after using Orderby and reflection :-

Beckham

ASP.NET MVC Preview 2

March 15, 2008 at 7:12 am | Posted in ASP.Net MVC, Java Script, jQuery | 1 Comment

ASP.NET MVC Preview 2 is released and you can download it from here.

In this CTP, A lot of changes happened in the MVC framework such as:

1- When you define a controller action method you don’t have to put the [ControllerAction] all you have to do is to define the method as public and it will be part of the contract, Okay but what if I wanted to define a non action method, well now you have to put an attribute J [NonAction].

2- Another thing is the {*catchall} The new * which allows you pass anything from the * to the end of the URL as a parameter for the action. And this is actually what I’m going to talk about in this post. But you can find a lot of stuff about the ASP.NET MVC Framework Preview 2 in Scott Hanselman Videos here.

In my previous post I bloged about ASP.NET MVC & JQuery, I was calling an action method which takes as a parameter the name of the category (In the Northwind database) to get the products for that category.

Well, the thing is some of the categories name contains “/” which as you already know is used in the URL, so it didn’t work. I overcome this issue by using Query String to pass in the parameter to the action method like that:

var url = ‘/Products/GetProducts?category=’+ categoryName;

But now with the new {*catchall} route rule it can be done.

routes.Add(new Route( “Products/GetProducts/ {*category}”,new MvcRouteHandler())

{
Defaults = new RouteValueDictionary (new

{

controller = “Products”,

action = “GetProducts”

}),

});

As you can see I used the {*category} not {*catchall} so catchall is not a keyword the * is the important part. But the important thing is whatever name you put after the {*} you must use the same name for the action method parameter.

For example, in the previous snippet I used:

“Products/GetProducts/{*category}

So in my Get Products action method I must pass in a category parameter like that:

public void GetProducts(string category)

{

}

The full source is attached.

P.S: To convert an MVC Application from Preview 1 to Preview 2 there is a lot of stuff and I mean “a lot” that you will have to change to get your application up and running and most of the changes will not be in your code. So if your application is a small one my advice is that create  a new application and just copy & paste your code in to it and now the changes that you will have to make is in your code J

But if your application big and hard to just copy & paste just follow the steps the release notes here.

Beckham

Next Page »

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.