A Better way to write Button Click actions in AS3

26 11 2009

If you ask me two of the most painful things while moving from as2 to as3 have been button actions and hyperlinking to a website.. and ironically those are the most common tasks for a flash designer/developer.

According to most of the blogs, forums and even the adobe site the way to code button actions with a hyperlink is like so

myButton_btn.addEventListener(MouseEvent.MOUSE_OVER, mysite);
function mysite(event:MouseEvent) {
var req1:URLRequest=new URLRequest("http://www.mysite.com");
navigateToURL(req1,"_self");
}

While this works great for a button or two, but if you have say a navigation bar of buttons or say hot spots on a map you are going to have to copy paste that whole code multiple times and keep changing the function name and url for each of them, which is totally going against DRY

In such situations I usually prefer to create a single function and pass the site link as a parameter to the function. The new code could look something like this

function siteLink (myurl:String):Function{
return function():void{
var req1:URLRequest=new URLRequest(myurl);
navigateToURL(req1,"_self");
}}
myButton_btn.addEventListener("mouseDown",siteLink("www.mysite.com"));
yourButton_btn.addEventListener("mouseDown",siteLink("www.yoursite.com"));

You could have this function on the first keyframe on the root and reuse the same function for buttons that you’d have within movieclips , you’ll need to slightly modify the code to this

var myroot = root;
ourButton_btn.addEventListener("mouseDown",myroot.siteLink("www.oursite.com"));

and if you need to call a function on a Mouse Over then the code would look like this

ourButton_btn.addEventListener("mouseOver",siteLink("www.oursite.com"));

Hope this helps





Apache or IIS not starting on Windows

7 11 2009

This seems to be a very common problem with many of us..

While trying to restart IIS  you suddenly start to get this message  “Unexpected error 0×8ffe2740 occurred.” or  your Apache on Windows would fail to start..

In most probable cases the culprit would be Skpe, so check to see if Skype is running and turn it off.

Try starting your IIS or Apache hopefully it should start now.. and after you have your IIS or Apache running then start Skype.

The reason for this is.. Skype by default looks to see if port 80 is free and if it is.. it will use port 80 to run.. and since both IIS and Apache also look for port 80 they fail if Skype has taken it up.

On the contorary if Port 80 is being used by either IIS or Apache, Skype will conveniently use another port.





A technique to prevent Phishing

11 09 2009

When I come to think of it.. stealing a persons credentials through phishing sites is going to be one of the biggest and most dangerous threat on the Internet.

Websites need to do  more than merely display warning messages on their sites in order to prevent phishing or alteast bring down the instances.

I think the basic concept is for the website to authenticate itself before the user puts in his/her passwords.

A simple technique that I thought of is described below

The login screen first displays only the textbox for the username, once the username is entered, the site makes an AJAX call and fetches the persons name and displays a message saying ” Hi Vinci Rufus” or some other info from the person’s profile before he/she can put in the passwords.

Well this does add an additional step, but I think it would be worth that extra step than losing your Internet Identity forever.

I’ve put up a small example of the above technique at this url

www.vinznet.com/labs/phishing/first_step.php

username : user@user.com     [ you can also hit tab]
pass: user

username: admin@admin.com
pass: admin

This is surely not a foolproof method and if the user doesn’t bother to look up on the screen to see if the site managed to get the correct info then there is nothing that can be done about it, or if the username is very similar to the persons name then we’ll need to pick up some other info like the birthdate or something.

So let me have your thoughts and ideas on the comments area and we can have a discussion.

I’m also thinking of another solution involving flash/flex based hologram kind of a thing.. but I’ll talk about it in another post.





Sorting by Color in Excel 2007

1 09 2009

I think one of the many requested features for Excel 2007 was Sorting your data based on color, and thankfully the Excel team has obliged to it.

Here are the settings to sort your data based on colors, very simple …very sweet !!!

sortByColor

Incase you want to add multiple sort criteria then simply click on the add button on the top left corner of the sort window





Counting unique items in an Excel List

30 08 2009

The other day a friend of mine asked me a supposedly simple question, but the answer wasn’t that straight forward

He wanted to get the count of unique items in a list , similar to the screenshot below

countUnique

The formula to get this would be

=SUMPRODUCT(1/(COUNTIF(A2:A12,A2:A12)))

Incase you want to extract a new list containing the unique records then you’ll need to use the Advanced Filter option located under Data > Filter

Just set options of the Advanced filter as shown in the screenshot and you should be done

FilterUnique

One thing to note is that for Advanced Filter the first row is treated as headings, so if the item in your first row was repeating .. it would show up twice in your new list.





Adding a Static Block in Magento

29 08 2009

Static Blocks are a great way to display banner ads notices or any  html content on various pages,

Its also fairly easy to work with.

1) Create the Static Block by going into CMS / Static Block and put your html content there. and give it a unique identifier like ” mybanner” or something like that.

Now if you want to add the banner within an CMS page that you simply need to write the following code to diplay the block there

{{block type="cms/block" block_id="mybanner"}}

However if you want the static block to be a part if your header or left column or the right one then you’ll need to go in an change the respective .phtml file

Say you want the static block on the left column then

Locate the left_col.phtml file it should be at this path

/app/design/frontend/default/default/template/callouts/left_col.phtml

open it up and add the following line where ever you want to display the block

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('mybanner')->toHtml() ?>

That should do the trick.
Oh and make sure you have Cache Disabled  all this while, otherwise its like banging your head against a brick wall !!
System > Cache Management




Excel 2003 commands in Excel 2007

23 08 2009

I guess moving from Excel 2003 to Excel 2007 has been a very unique experience for all of us including me.  Its like you buy this new shiny car and as you step in you are like ” emm Where’s the steering wheel and … where did the accelerator and brakes go?”

The first few weeks or months  with Excel 2007 can be quite unnerving as you try to re-learn as to where all the commands have gone.

To be honest the new ribbon is actually a more logical grouping of the menus and commands, but since we’ve used to what was totally illogical for all these years it gets frustrating.

Anyways the Excel 2007 Cheat Sheet located here helped me get through my initial days and many a times even now.  I thought I’d share this with you incase you didnt already know about it.

Happy re-learning !!





Integrating the Magento LiveChat Extention

6 08 2009

Most Shopping Sites need a Live Chat to help the visitors get their questions answered

Mangento has a faily popular extention called the MagentoLiveChat Available here

http://www.magentocommerce.com/extension/808/livechat

Creating the Operatior can get a little tricky so follow the steps here

http://www.magentocommerce.com/wiki/modules_reference/english/beck_livechat/operator_list/index





Replacing blank cells with 0 in Excel 2007

4 08 2009

This is a very common requirement for many of us, and there are multiple ways to achieve this many of which requires running macros, but the easiest way that I follow is following these steps :

1) On the “Home” tab >Select the “Find and Select” dropdown menu ( on the Editing Group of icons)

2) Select “Go to Specials” and select the “Blanks” radio button and say “OK”

3) Type 0 or  any character that you want to replace the blanks with

4) Press Ctrl+Enter

.. and you are done





Adding a new Layout in Mangento 1.3.2.1

2 08 2009

If you need to create a new layout for a Mangeto Site, its not a straight forward thing..
Here are the steps you need to follow.
First create the layout file.. I’m calling mine as home.phtml located at
design\frontend\default\default\template\page\home.phtml

Then you need to go in and edit the config.xml file located at
/app/code/core/Mage/Page/etc/config.xml

and add in the xml tags as follows within the < layouts >tag

<Homepage module="page" translate="label">
<label>Homepage</label>
<template>page/home.phtml</template>
<layout_handle>Homepage</layout_handle>
</Homepage>

Upload the files and in the admin when you edit the page under CMS and go into Custom Design you should now able to see the Homepage under the layouts drop down