Hi All. Let me tell you how to invoke an ActionScript function from a JavaScript function in Adobe Flex. Just download the InvokeASfromJS.rar project folder from the box that appears at the extreme bottom of this blog and follow the below things.
Project Details:
1)This “InvokeASfromJS”[AS-> ActionScript,JS-> JavaScript] project is a shows how to invoke ActionScript code from JavaScript in Flex.
2)This application includes Flex UI components Panel and Button.
a)Panel – to display Button
b)Button – to invoke a JavaScript function, which in turn invokes an ActionScript function
3)This project needs the developer to modify index.template.html file which is inside the html-template folder.
NOTE: Steps 4 through 6 are already done in this project and need not to repeat. Do these steps 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 line “<script language=”JavaScript” src=”externalInterface.js”></script>”.
5)Now create a file called externalInterface.js in src folder.
6)externalInterface.js file should have the JavaScript function which is called by and which calls the ActionScript file.
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 main.mxml file inside src folder.
How it works?
1) Run main.mxml file inside the src folder.
2) Click ActionScript –> JavaScript –> ActionScript button in the Panel.
3) Now an alert box appears with a message “ActionScript invoked from JavaScript”.
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