Embed HTML code or page (Flex IFrame) in Flex (Flash) _flex

Source: Internet
Author: User
Tags cdata http request

Embed the HTML code in the Flex component to make use of flex iframe. This is a lot of time to use, sometimes flex has to do so, if you do not do it ...

Flex is also capable of JavaScript interaction with HTML, Flex calls to JavaScript methods in HTML, and gets the return value after the call.

1, Flex iframe Download Address: Https://github.com/downloads/flex-users/flex-iframe/flex-iframe-1.5.1.zip

After the download is complete the following directory

Asdoc is Doc.
The bin has a flex library that needs to be used SWC
Examples is the example
Sources source Code

2, the bin directory SWC into your flex project, and add code snippet as follows

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml"
Xmlns:flexiframe= "http://code.google.com/p/flex-iframe/"
horizontalalign= "center" verticalalign= "Middle" xmlns:s= "Library://ns.adobe.com/flex/spark" >

<mx:Script>
<! [cdata[
Import Mx.controls.Alert;
protected function Sayhellohandler (event:mouseevent): void {
Invoke the SayHello JavaScript method in the current IFRAME embedded page
Iframebysource.calliframefunction ("SayHello");
}

protected function Sayhandler (event:mouseevent): void {
Invokes the say JavaScript method in the current iframe embedded page and passes in a parameter
Iframebysource.calliframefunction ("Say", ["Hello world!"]);
}
protected function Sayhihandler (event:mouseevent): void {
Invokes the Sayhi JavaScript method in the current iframe embedded page and passes in 2 parameters. The Sayhi method returns a string, and the last callback is the function that outputs the value
Iframebysource.calliframefunction ("Sayhi", ["Hello World", "Dick"], Function (data:*): void {
Alert.show (data);
});
}
]]>
</mx:Script>

<!--HTML content stored in a String-->
<mx:string id= "Iframehtmlcontent" >
<! [cdata[
<title>About</title>
<body>
<div>About</div>
<p>simple HTML Test Application. This test app loads a page of HTML locally.</p>
<div>Credits</div>
<p> </p>
<p>iframe.as is based on the work of</p>
<ul>
<li><a href= "http://coenraets.org/" target= "_top" >christophe coenraets</a></li>
<li><a href= "http://www.deitte.com/" target= "_top" >brian deitte</a></li>
</ul>
</body>
]]>
</mx:String>

<mx:panel width= "80%" height= "80%" title= "Use source local remote page" >
<flexiframe:iframe id= "Iframebysource" width= "100%" height= "100%" source= "frame.html"/>
<s:button label= "SayHello" click= "Sayhellohandler (event)"/>
<s:button label= "Say-param" click= "Sayhandler (event)"/>
<s:button label= "Sayhi" click= "Sayhihandler (event)"/>
</mx:Panel>

<mx:panel width= "80%" height= "80%" title= "Load Remote page with source" >
<flexiframe:iframe id= "Iframebyremotesource" width= "100%" height= "100%" source= "http://www.baidu.com" True
Overlaydetection= "true"/>
</mx:Panel>

<mx:panel width= "80%" height= "80%" title= "loading local HTML text content with the content property" >
<flexiframe:iframe id= "iframebycontent" width= "100%" height= "100%" content= "{iframehtmlcontent}"/>
</mx:Panel>

</mx:Application>

Frame.html page Content
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>frame.html</title>
<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Cache-control" content= "No-cache" >
<meta http-equiv= "Expires" content= "0" >
<script type= "Text/javascript" >
No parameters
function SayHello () {
Alert ("Hello ...");
}

1 parameters
function say (message) {
Alert ("Your SAY:" + message);
}

Multiple parameters and return values
function sayhi (message, name) {
Alert ("Your SAY:" + message + ", Name:" + name);
Return "Your SAY:" + message + ", Name:" + name;
}
</script>


<body>
Flex Frame Example HTML page!
<input type= "button" value= "Say" onclick= "SayHello ()"/>
</body>

Note that your Flex Project project needs to be published to HTTP application servers (such as Tomcat, JBoss, IIS), which can be invoked on HTTP requests to page content and JavaScript methods. If you do not publish to the application server, you can only embed a remote HTTP request page in the IFRAME, and the local static page cannot be displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.