Flexi.as
资源名称:Flexi.zip [点击查看]
上传用户:szxykj
上传日期:2009-10-05
资源大小:322k
文件大小:6k
源码类别:
FlashMX/Flex源码
开发平台:
Flex
- /*
- * Flexi
- * v1.2
- * Arcadio Carballares Martin, 2009
- * http://www.arcadiocarballares.com
- */
- package com.arcadiocarballares {
- import flash.external.ExternalInterface;
- import flash.geom.Point;
- import mx.containers.Box;
- import mx.core.Application;
- import mx.core.Container;
- import mx.events.FlexEvent;
- import mx.events.MoveEvent;
- import mx.events.ResizeEvent;
- import mx.events.ScrollEvent;
- public class Flexi extends Box {
- [Bindable]
- public var url:String="http://www.carballares.es/arcadio";
- [Bindable]
- public var border:int=0;
- private var contX:Boolean=false;
- private var contY:Boolean=false;
- public function Flexi() {
- super();
- }
- public function hideIFrame():void {
- var action:String="function () {" +
- "document.getElementById('FlexIframe"+name+"').style.display='none';"+
- "}";
- ExternalInterface.call(action);
- }
- public function showIFrame():void {
- var action:String="function () {" +
- "document.getElementById('FlexIframe"+name+"').style.display='block';"+
- "}";
- ExternalInterface.call(action);
- }
- override protected function measure():void {
- super.measure();
- // Script to create the IFRAME which contain HTML 'url'
- var action:String="function () {" +
- "var FlexIframe=document.createElement('iframe');" +
- "FlexIframe.id='FlexIframe"+name+"';" +
- "FlexIframe.style.position='absolute';" +
- "FlexIframe.frameBorder='"+border+"';" +
- "FlexIframe.src='"+url+"';" +
- "document.getElementsByTagName('body')[0].appendChild(FlexIframe);" +
- "}";
- // Control scroll events
- Application.application.addEventListener(ScrollEvent.SCROLL, updateDimensions);
- Container(owner).addEventListener(FlexEvent.CREATION_COMPLETE, updateDimensions);
- Container(owner).addEventListener(ResizeEvent.RESIZE, updateDimensions);
- Container(owner).addEventListener(MoveEvent.MOVE, updateDimensions);
- ExternalInterface.call(action);
- //getContainers(this);
- getContainers(Container(owner));
- }
- private function updateDimensions(event:Event=null):void {
- if (this==null) {return};
- var dimensions:Object=getDimensions();
- var pos:Point=Container(owner).localToGlobal(new Point(0,0));
- var left:int=int(pos.x);
- var top:int=int(pos.y);
- var myWidth:int=int(dimensions.myWidth);
- var myHeight:int=int(dimensions.myHeight);
- var action:String="function () {" +
- "document.getElementById('FlexIframe"+name+"').style.left="+left+"+'px';"+
- "document.getElementById('FlexIframe"+name+"').style.top="+top+"+'px';"+
- "document.getElementById('FlexIframe"+name+"').style.width="+myWidth+";"+
- "document.getElementById('FlexIframe"+name+"').style.height="+myHeight+";"+
- "}";
- ExternalInterface.call(action);
- }
- private function getContainers(cont:Container):void {
- /*
- Check 'parent' with fixed dimensions and containers with 100% dimensions
- because they cause 'move' and 'resize' events and attach them a listener.
- Function is recursive until it adds all listeners or reaches superior level.
- */
- if (cont is Container && contX==false && contY==false) {
- if (isNaN(cont.percentWidth) && contX==false && esContenedorValido(cont)) {
- cont.parent.addEventListener(MoveEvent.MOVE, updateDimensions);
- contX=true;
- }
- if (isNaN(cont.percentHeight) && contY==false && esContenedorValido(cont)) {
- cont.addEventListener(MoveEvent.MOVE, updateDimensions);
- contY=true;
- }
- getContainers(cont.parent as Container);
- }
- }
- private function esContenedorValido(cont:Object):Boolean {
- var isValid:Boolean=true;
- // Containers than doesn't dispatch 'move' or 'resize' events
- switch (Container(cont).className) {
- case "GridItem":
- isValid=false;
- break;
- case "GridRow":
- isValid=false;
- break;
- }
- return isValid;
- }
- private function getDimensions():Object {
- var dimensions:Object=new Object();
- dimensions.myWidth=100;
- dimensions.myHeight=100;
- if (width) {
- dimensions.myWidth = width;
- } else {
- if (isNaN(percentWidth)) {
- dimensions.myWidth = Container(owner).width;
- } else {
- dimensions.myWidth = Container(owner).width
- -int(Container(owner).getStyle('paddingLeft'))
- -int(Container(owner).getStyle('paddingRight'));
- if (Container(owner).getStyle('borderStyle')=='solid') {
- dimensions.myWidth=dimensions.myWidth
- -int(Container(owner).getStyle('borderThickness'))
- -int(Container(owner).getStyle('borderThickness'));
- }
- }
- }
- if (height) {
- dimensions.myHeight = height;
- } else {
- if (isNaN(percentHeight)) {
- dimensions.myHeight = Container(owner).height;
- } else {
- dimensions.myHeight = Container(owner).height
- -int(Container(owner).getStyle('paddingTop'))
- -int(Container(owner).getStyle('paddingBottom'));
- if (Container(owner).getStyle('borderStyle')=='solid') {
- dimensions.myHeight=dimensions.myHeight
- -int(Container(owner).getStyle('borderThickness'))
- -int(Container(owner).getStyle('borderThickness'));
- }
- }
- }
- return dimensions;
- }
- }
- }