Hi All. Let me tell you how to invoke a JavaScript function from Action Script in Adobe Flex. Just download the InvokeJSfromASwithParam.rar project folder from the box that appears at the extreme bottom of this blog and follow the below things.
Project Details:
1)This “InvokeJSfromASwithParam”[AS-> Action Script, JS-> JavaScript] project shows how to invoke JavaScript function with parameters from Action Script in Flex.
2)This application includes Flex UI components Panel and Button.
a)Panel – to display Button
b)Text Boxes – to get input from user
c)Button – to invoke a JavaScript function
3)This project needs the developer to modify index.template.html file which is in the html-template folder.
NOTE: Steps 4 and 5 are already done in this project and need not to repeat. Do it only if you are creating your own project.
4)Open index.template.html file in a text editor and between the <body> tags include the following lines
<script language=”JavaScript” type=”text/javascript”>
function addTwoNumbers(a,b)
{
var c = parseInt(a)+parseInt(b);
alert(“Sum of “+a+” and “+b+” : “+c);
return c;
}
</script>
5)You can replace addTwoNumbers(a,b) function with your own function.
Follow these steps to run PhotoShow project in FlexBuilder:
1) Open the Code folder and copy all the files.
2) Create a new project in FlexBuilder and paste the those files inside the newly created Flex project folder.
3)Replace the already existing files(if any) in the newly created project folder with the copied files.
4)Save the project and run the InvokeJSWithParam.mxml file inside src folder.
How it works?
1) Run InvokeJSWithParam.mxml file inside the src folder.
2) Enter two numbers in the two text input boxes[one number in each text input box].
2) Click Add button in the Panel.
3) Now a JavaScript alert box appears with a message “sum of 10 and 20 : 30″[say you have entered 10 and 20 in text input boxes].
To know more about my micro lectures in Flex and to stay in touch with me please visit my website
http://www.snipersn.ucoz.com