Html pages on the flex application : “importing a html page to flex app”
Importing a html page from a server or through database is a easy job with some upgradation of the html page generated by the flex application.
Here we can use a concept of IFrame’s ,persons who has basic knowledge of html knows it.
At first i want to import a google page in to my flex application than i start the code like this.
1.define a iframe component in flex of type canvas, it contains get and set methods which are used to set and get the source of the html page, and
other methods for moving the iframe and soure set.here we use ExternalInterface.
The code any iframe is similar to that of below one.
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml”
resize=”callLater(moveIFrame)”
move=”callLater(moveIFrame)”>
<mx:Script>
<![CDATA[
import flash.external.ExternalInterface;
import flash.geom.Point;
import flash.net.navigateToURL;
private var __source: String;
/**
* Move iframe through ExternalInterface. The location is determined using localToGlobal()
* on a Point in the Canvas.
**/
private function moveIFrame(): void
{
var localPt:Point = new Point(0, 0);
var globalPt:Point = this.localToGlobal(localPt);
ExternalInterface.call("moveIFrame", globalPt.x, globalPt.y, this.width, this.height);
}
/**
* The source URL for the IFrame. When set, the URL is loaded through ExternalInterface.
**/
public function set source(source: String): void
{
if (source)
{
if (! ExternalInterface.available)
{
throw new Error("ExternalInterface is not available in this container. Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime are required.");
}
__source = source;
ExternalInterface.call("loadIFrame", source);
moveIFrame();
}
}
public function get source(): String
{
return __source;
}
/**
* Whether the IFrame is visible.
**/
override public function set visible(visible: Boolean): void
{
super.visible=visible;
if (visible)
{
ExternalInterface.call("showIFrame");
}
else
{
ExternalInterface.call("hideIFrame");
}
}
]]>
</mx:Script>
</mx:Canvas>
2.now upgrading the generated html files of ur flex application.For example if u create ur project as IFrameDemo than the html page is IFramDemo.html in the bin folder ( Iam spoon feeding i think ) and another html file is IFrameDemo-debug.html in bin folder and another html file index.template.html in html-template folder.
so these three html files u have to make changes(Note: these file are generated on creation of project no need to create again).
The three changes u have to make in these three html files is
1. wmode set to opaque at AC_FL_RunContent(); mehtod and in <object> tag
2. the moveIFrame,hideIFrame,showIFrame,loadIFrame methods including in the script tag
3. the ‘myFrame’ div adding at the bottom
the code for secound point:
<script language=”JavaScript” type=”text/javascript”>
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
function moveIFrame(x,y,w,h) {
var frameRef=document.getElementById(“myFrame”);
frameRef.style.left=x;
frameRef.style.top=y;
var iFrameRef=document.getElementById(“myIFrame”);
iFrameRef.width=w;
iFrameRef.height=h;
}
function hideIFrame(){
document.getElementById(“myFrame”).style.visibility=”hidden”;
}
function showIFrame(){
document.getElementById(“myFrame”).style.visibility=”visible”;
}
function loadIFrame(url){
document.getElementById(“myFrame”).innerHTML = “<iframe id=’myIFrame’ src=’” + url + “‘frameborder=’0′></iframe>”;
}
</script>
the code for 3rd point div tag:
<div id=”myFrame” style=”position:absolute;background-color:transparent;border:0px;visibility:hidden;”></div> at bottom of the page
Note:
these changes in all the three html pages
3.including the iframe component at the application
<mx:Panel width=”100%” height=”100%” title=”Content Pane” paddingTop=”1″ paddingBottom=”1″ paddingLeft=”1″ paddingRight=”1″ >
<mx:Canvas width=”100%” height=”100%”>
<IFrame id=”iFrame” x=”0″ y=”0″ width=”100%” height=”100%” >
</IFrame>
</mx:Canvas>
in script tag put iFrame.source=”www.google.com/”; to view the result. it displays google page at the flex application.
As u can see the below inamge the panel contains an iframe where my html pages resides