Form elements in Javascript

We are working on a new project and we needed to create the array of form elements in Javascript. After googling for some time we found out that we can access all the form elements in document.formName.elements

Following code loops through the form and creates an associative array of form elements:

function getFormElements()
{
    frmElmts = new Array();
    for(i=0; i<document.formName.elements.length; i++)
    {
         frmElmts[document.formName.elements[i].name] = document.formName.elements[i].value;
    }
}

Calling Javascript functions from Flash

Calling Javascript functions from Flash is very easy. We use a class called ExternalInterface. Here is ActionScript code:

import flash.external.*;
import flash.events.Event;

button1.addEventListener(MouseEvent.CLICK, buttonHandle);

function buttonHandle(event:MouseEvent)
{
    ExternalInterface.call("showMessage");
}

Here flash.external is a package where the class ExternalInterface is found.
The code is very simple. Event listener to button is added. And call is a method of ExternalInterface class, the parameter passed to call() is a name of the Javascript function.

The Javascript function is an alert message:

function showMessage()
{
    alert("Hi from flash");
}

Javascript function called from Flash