Friday, June 25

Calling a Javascript in Flex


Steps to call a javascript from Flex.

Step 1:
Create a New Flex Project in a Flex Builder with Application type “None”.

Step 2:
Then MXML file will be opened and ready to start.

Go to Design View

Step 3:
Drag a Button from the Flex Component.

Step 4:
Change the label of the Button and add click event to the button using the function name.

Step 5:
Add a simple script in Flex code View.

For Calling a Javascript in Flex, we have to use ExternalInterface.

Call refers to calling a javascript and hello is nothing but the function name in the javascript.

Code looks like this,

      


Step 6:
Now,here is the actual problem arise.

Where to put the javascript code.

But its quite simple,here it is.

In your Flex Project,you have a directory called “html-template”.

In that you will have “index.template.html”.

In that file,before the closing of head tag you have to place your Javascript code.

Sample JavaScript code


function hello() { alert(“Call from Javascript”); }


Thats it all done.

Output

No comments:

Post a Comment