call a flex app function from javascript or wrapper html page

To call a function in flex app from java script or html wrapper we need to use a function of ExternalIntrface API the function name is addCallback()
the syntax of the function is given below
here  myFunction is the function which is called when an instance is returned from the JS i’e “getarg”
this statement should be in public function of flex app
and the function we call myFunction should also be public.
public funciton init():void

public function myFunction(s1:String):void
var s:String=new String();
s=s1;” “+s,”Title”);

The above lines of code are for flex app, Now to raise the function myFunction from wrapper page we have to include the following lines of statements
<body onload=’callEx()’>
<script …..>
function callEx()

here the mymxml is the “name” and “id” of the <Object> and tags by default they are created but we have to change to give them periods as they don’t have when the body loads the function callEx() is called and title of the page is passed to the flex page there we are getting it in a string and Alert it.
thats it calling a function from the JS.


One Response to call a flex app function from javascript or wrapper html page

  1. Ganesh says:

    Hi Kumar..
    I am very new to Flex environment.
    I have a doubt on calling a Java Script that is placed in a differnt location..

    For example..

    I have my .mxml file in root/mymXml/One.mxml

    Now in this One.mxml i want to use a java script..But that java script is in some other location

    example… root/myjs/Sc.js

    Now…in that Sc.js i have a method called validate();

    how to call this method from One.mxml

    I tried
    ExternalInterface…but it accpets the scripts it those scripts are in the same page…i mean with in One.mxml

    Can u kindly guide me..


    Ganesh K Thiagarajan

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: