import flash.external.ExternalInterface; import flash.geom.Point; import flash.net.navigateToURL; private var __source: String; 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); } public function set source(source: String): void { if (source) { if (! ExternalInterface.available) { // TODO: determine if this Error is actually needed. The debugger // build gives the error below. Assuming that this error will not show // up in the release build but haven’t checked. throw new Error("The 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); } }
//Flash场景0,0坐标 var localPt:Point = new Point(0, 0); //转换为浏览器页面坐标 var globalPt:Point = this.localToGlobal(localPt); 这样就可以在Flex页面中嵌入任意的HTML页面了,为了方便,Brian写了个嵌入HTML页面的代理IFrame组件,该组件封装了所有需要的Flex端代码:
resize="callLater(moveIFrame)" move="callLater(moveIFrame)"> import flash.external.ExternalInterface; import flash.geom.Point; import flash.net.navigateToURL; private var __source: String; 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); } public function set source(source: String): void { if (source) { if (! ExternalInterface.available) { // TODO: determine if this Error is actually needed. The debugger // build gives the error below. Assuming that this error will not show // up in the release build but haven’t checked. throw new Error("The 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); } } public function get source(): String { return __source; } override public function set visible(visible: Boolean): void { super.visible=visible; if (visible) { ExternalInterface.call("showIFrame"); } else { ExternalInterface.call("hideIFrame"); } }