Here to do this we have to use the ExternalInterface API.
call() Method of this Class will help doing this.
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”init()”>
<mx:Script>
<![CDATA[
private function init():void
{
ExternalInterface.call("alertfromJS");
}
]]>
</mx:Script>
</mx:Application>
Here in the above code we are calling a function in the Javascript of the html page.on initilizing of the App.
The function is alertfromJS which we have to define at the Html page and in the JS block.
And that would be:-
<script language=”JavaScript” type=”text/javascript”>
function alertfromJS()
{
alert(“kumar Gandhi”);
}
</script>
So now when u run the App , a alert box from Javascript will appear with text KumarGandhi.
A good programmer will always have an eye on the html wrapper generated by the Flex App.


May 11, 2009 at 7:08 am |
Hi Kumar,
I have one problem, i want to use Iframe in my flex application to call many JSP files inside that Iframe. I written java script code in html file which is inside bin-debug folder and its working fine.
Now problem is that when i clean or compile project, then old HTML file is get deleted and it will create new HTML file bcoz of this i am not getting my old JavaScript code in HTML file.
So will u plz tell me the solution for this………..?
Thanx in advance…..
Regards,
Pradip Jadhav
May 11, 2009 at 1:56 pm |
Hi Pradip,
The HTML files in the bin-debug or bin-release are created using the template files in the html-template folder of your project, so every time you compile,build or clean the project,the template files are used to create a new set of HTML files to the corresponding.So the solution is , what ever code you want to include in the HTML files just include them in the template files as they are used for creating a new ones.The file in the html-template folder used to create the App HTML file is index.template.html, so make changes to this file,not to the APP html files in the bin-debug folder or bin-release folder. Hope this helps you.
regards,
kumar.
August 7, 2009 at 10:35 am |
[...] this Post on the [...]