flex中有时候要动态加载页面! 在flex2.0中加载页面比较麻烦,幸运的是flex3.0中有IFrame可以简单的加载页面!
第一步:去http://code.google.com/p/flex-iframe/ 下载最新版本的IFrame.解压后找到IFrame.as脚本,copy到你的flex工程中的src文件下确保你的工作中有此as脚本。
第二步:就可以直接使用IFrame组件了!我的测试案例如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="AS.*" backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#150303, #150303]" >
<mx:Script>
<![CDATA[
import AS.IFrameExternalCalls;
[Bindable]
private var path:String="";
private function onClick(e:MouseEvent):void
{
iframe.visible=true;
if(e.currentTarget==lb)
iframe.source="http://www.sina.com";
else if(e.currentTarget==lbwy)
iframe.source="http://www.163.com";
}
]]>
</mx:Script>
<mx:Panel title="FLEX嵌入jsp页面" top="2" left="2" width="100%" height="100%" backgroundColor="#D7BCBC" fontSize="15">
<mx:ApplicationControlBar height="71" id="acb" width="100%">
<mx:LinkButton id="lb" label="去新浪看看" width="156" height="51" click="onClick(event)"/>
<mx:LinkButton id="lbwy" label="去163看看" width="156" height="51" click="onClick(event)"/>
</mx:ApplicationControlBar>
<local:IFrame id="iframe" x="{acb.x}" y="{acb.y+acb.height+10}" label="iframe嵌入界面" width="100%" height="98%"
backgroundColor="#EBA9A9" visible="false" source="{path}">
</local:IFrame>
</mx:Panel>
</mx:Application>
运行结果如下: