百度空间 | 百度首页 
 
查看文章
 
在Flex中嵌入完整HTML页面
2009-03-30 15:28

效果展示:http://www.deitte.com/IFrameDemo3/IFrameDemo.html
源码下载:http://www.deitte.com/IFrameDemo3/srcview/index.html

demo

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="iFrame.visible=true" viewSourceURL="srcview/index.html"> 

    <mx:HBox width="100%" height="100%">

        <mx:Panel title="Tree" width="200" height="100%" roundedBottomCorners="true">
             <mx:Tree id="tree" width="100%" height="100%" dataProvider="{treeData}"
                     labelField="@label" showRoot="false"
                     change="iFrame.source = (Tree(event.target).selectedItem.attribute(&apos;path&apos;).toString());"  />
        </mx:Panel>

        <mx:Panel width="100%" height="100%" title="Content" paddingTop="1" paddingBottom="1" paddingLeft="1" paddingRight="1" >
            <IFrame id="iFrame" source="http://www.adobe.com/devnet/flex/" width="100%" height="100%"  />
            <mx:ControlBar>
                <mx:CheckBox id="cbVisible" label="IFrame Visible" selected="true" click="iFrame.visible=cbVisible.selected"/>
            </mx:ControlBar>
        </mx:Panel>

    </mx:HBox>

    <mx:XMLList id="treeData">
        <node label="Flex Resources">
            <node label="Flex Developer Center" path="http://www.adobe.com/devnet/flex/" />
            <node label="Flex Team Blog" path="http://weblogs.macromedia.com/flexteam/" />
            <node label="Flex Blogs on MXNA" path="http://weblogs.macromedia.com/mxna/FeedList.cfm#Flex" />
            <!-- these sites pop themselves out of a frame:
            <node label="flex.org" path="http://www.flex.org" />
            <node label="Adobe Labs" path="http://labs.adobe.com/wiki/index.php/Main_Page" />
            -->
        </node>
        <node label="Search">
            <node label="Google" path="http://www.google.com" />
            <node label="Yahoo" path="http://www.yahoo.com" />
        </node>
    </mx:XMLList>

</mx:Application>
 
//IFrame
<?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>

类别:代码收集 | 添加到搜藏 | 浏览() | 评论 (1)
 
最近读者:
 
网友评论:
1
2009-09-08 20:02 | 回复
不好意思!我想請問一下
為什麼我照你的程式碼貼上後,點擊左邊tree下的東西,右邊的content沒有東西出現
可以麻煩您一下嗎
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu