In this application, there are two files, FlexJsCommunication.mxml and sample.html. It will load sample.html file inside flex application using HTMLLoader. sample.html file is initially blank. When we browse a folder, it will load all images from that folder to sample.html page.
In this application we call loadImagesFromFlex() by using htmlLoader.window.loadImagesFromFlex(files[i].nativePath);
It is taking image path as parameter and loading the image inside sample.html file.
While loading sample.html file, we have added an eventlistener for Event.HTML_DOM_INITIALIZE event. The HTMLDOMInitialize event is dispatched before any objects are created in the new HTML window or DOM. This gives us opportunity to create and initialize variables that objects in the new window can use. Since objects are not created yet, you can’t access them when this event is dispatched.
In HTMLDOMInitialize listener function, we assign
htmlLoader.window.sendImgPathToFlex = getSelectedImgPath;.
So when we call sendImgPathToFlex function in sample.html file, it will automatically execute getSelectedImgPath method. Here both the methods have same number of parameters. sendImgPathToFlex function is called when we mouseover on any image in sample.html. sendImgPathToFlex calls the getSelectedImgPath and loads the image inside the application.
You can download the example file from this link.
Article by : Sushil Kumar Sahoo
Linkedin | Stackoverflow