Flash舞台随窗口大小动态调整.docx
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Flash 舞台 窗口 大小 动态 调整
- 资源描述:
-
本文介绍如何建立一个舞台随窗体尺寸大小动态改变的Flash例子,使用的脚本为AS3.0 1. 建立工程 2. 新建一个AS文件,主要实现舞台的动态缩放功能 代码如下: package { import flash.display.Sprite; import flash.display.Stage; import flash.events.Event; import flash.external.ExternalInterface; public class BrowserCanvas { public static const HACK_MARGIN_BOTTOM:String = "marginBottom"; //Adds a negative bottom margin to object tags to compensate for browser weirdness public static const HACK_IE_REPARENT:String = "IEReparent"; //In IE, create a container div which encapsulates the object tag in order to hav min/max sizes work public static const HACK_UNIQUE_ID:String = "uniqueId"; //If you put both an embed and object tag with the same id, this tries to compensate private var stage:Stage; private var containerId:String; private var _width:String; private var _minWidth:String; private var _maxWidth:String; private var _height:String; private var _minHeight:String; private var _maxHeight:String; private var timerSprite:Sprite; public function BrowserCanvas ( stage:Stage,containerId:String=null , browserHacks:Array=null ) { trace("BrowserCanvas - Copyright (c) 2008 Noel Billig ()"); this.stage = stage; timerSprite = new Sprite(); _width = String( stage.stageWidth ); _height = String( stage.stageHeight ); if (browserHacks == null) browserHacks = [HACK_MARGIN_BOTTOM,HACK_IE_REPARENT,HACK_UNIQUE_ID]; this.containerId = containerId; if (this.containerId == null) this.containerId = ExternalInterface.objectID; if (this.containerId == null) this.containerId = ExternalInterface.call(JSScripts.GET_FLASH_ID, stage.loaderInfo.url); if (browserHacks.length != 0) { this.containerId = ExternalInterface.call(JSScripts.INSERT_BROWSER_HACKS, this.containerId, browserHacks.join(",")); } } public function set width(newWidth:String):void { this._width = formatSize(newWidth); invalidate(); } public function set minWidth(newWidth:String):void { this._minWidth = formatSize(newWidth); invalidate(); } public function set maxWidth(newWidth:String):void { this._maxWidth = formatSize(newWidth); invalidate(); } public function set height(newHeight:String):void { this._height = formatSize(newHeight); invalidate(); } public function set minHeight(newHeight:String):void { this._minHeight = formatSize(newHeight); invalidate(); } public function set maxHeight(newHeight:String):void { this._maxHeight = formatSize(newHeight); invalidate(); } private function formatSize(size:String):String { if (size == null) return ""; //Null causes opera to never clear the appropriate values, so use empty string return (int(size) == 0) ? size : size+"px"; } private function invalidate():void { timerSprite.addEventListener(Event.ENTER_FRAME,update); } private function update(event:Event):void { timerSprite.removeEventListener(Event.ENTER_FRAME,update); ExternalInterface.call(JSScripts.RESIZE_CONTAINER,containerId,_width,_height,_minWidth,_minHeight,_maxWidth,_maxHeight); } } } class JSScripts { public static var GET_FLASH_ID:XML = <script><![CDATA[ function(swfFullPath) { var getFileName = function(fullPath) { var ary = fullPath.split("/"); var fileName = ary[ary.length-1].split(".swf")[0]; return fileName; } var ensureId = function(node) { if (node.attributes["id"] == null) { node.setAttribute("id",'swf'+new Date().getTime()); } } var matchesTarget = function(fullPath) { return (getFileName(fullPath) == targetSwfName); } var targetSwfName = getFileName(swfFullPath); //Look through the embed nodes for one that matches our swf name var nodes = document.getElementsByTagName("embed"); for (var i=0; i < nodes.length; i++) { //Parse just the SWF file name out of the whole src path and check if it matches if (matchesTarget(nodes[i].attributes["src"].nodeValue)) { ensureId(nodes[i]); return nodes[i].attributes["id"].nodeValue; } } //If we haven't found a matching embed, look through the object nodes nodes = document.getElementsByTagName("object"); for (var j=0; j < nodes.length; j++) { //Check if the object tag has a data node if (nodes[j].attributes["data"] != null) { if (matchesTarget(nodes[j].attributes["data"].nodeValue)) { ensureId(nodes[j]); return nodes[j].attributes["id"].nodeValue; } } //Grab the param nodes out of this object, and look for one named "movie" var paramNodes = nodes[j].getElementsByTagName("param"); for (var k=0; k < paramNodes.length; k++) { if (paramNodes[k].attributes["name"].nodeValue.toLowerCase() == "movie") { if (matchesTarget(paramNodes[k].attributes["value"].nodeValue)) { ensureId(nodes[j]); return nodes[j].attributes["id"].nodeValue; } } } } return null; } ]]></script>; public static var INSERT_BROWSER_HACKS:XML = <script><![CDATA[ function (containerId,browserHacks) { var objNode = document.getElementById(containerId); if (objNode.nodeName.toLowerCase() == "div") return; //If you make the mistake of naming the object and embed nodes with the same id, firefox will get confused if ( ((navigator.userAgent.toLowerCase().indexOf("firefox") != -1) || (navigator.userAgent.toLowerCase().indexOf("opera") != -1)) && (objNode.nodeName.toLowerCase() == "object") && (browserHacks.indexOf("uniqueId") != -1) ) { //Check if we have an embed tag inside of us, if so, ignore the obj tag var newNode = objNode.getElementsByTagName("embed")[0]; if (newNode != null) { newNode.setAttribute("id",objNode.attributes["id"].nodeValue); objNode.attributes["id"].nodeValue += new Date().getTime(); objNode.attributes['width'].nodeValue = "auto"; objNode.attributes['height'].nodeValue = "auto"; objNode.style.width = ""; objNode.style.height = ""; objNode = newNode; } } //All of the browsers but IE seem to put a margin underneath all object/embed tags. //Seems like a bug, but it's suspicious that it's a problem in all browsers but IE. if ( (navigator.userAgent.toLowerCase().indexOf("msie") == -1) && (browserHacks.indexOf("marginBottom") != -1) ) { if (navigator.userAgent.toLowerCase().indexOf("opera") != -1) { objNode.style.marginBottom = "-4px"; } else { objNode.style.marginBottom = "-5px"; } } //IE has a bug where it doesn't respect the min-height/max-width style settings on an object tag //To work around this, we reparent the object tag into a div, and use the ref to the div instead. if ( (navigator.userAgent.toLowerCase().indexOf("msie") != -1) && (objNode.nodeName.toLowerCase() == "object") && (browserHacks.indexOf("IEReparent") != -1) ) { //Insert a parent div above the object node var newId = "swfContainer"+(new Date().getTime()); divNode = document.createElement('div'); objNode.parentNode.insertBefore(divNode,objNode); divNode.setAttribute('id',newId); divNode.appendChild(objNode); //Set the parent div to the size of the object node, and the object node to 100% var getFormattedValue = function(val) { if ((val.indexOf("px") == -1) && (val.indexOf("%") == -1)) return val+"px"; return val; } divNode.style.width = getFormattedValue(objNode.attributes['width'].nodeValue); divNode.style.height = getFormattedValue(objNode.attributes['height'].nodeValue); objNode.attributes['width'].nodeValue = "100%"; objNode.attributes['height'].nodeValue = "100%"; return newId; } return containerId; } ]]></script>; public static var RESIZE_CONTAINER:XML = <script><![CDATA[ function(containerId,width,height,minWidth,minHeight,maxWidth,maxHeight) { var objNode = document.getElementById(containerId); objNode.style.width = width; objNode.style.height = height; objNode.style.minWidth = minWidth; objNode.style.minHeight = minHeight; objNode.style.maxWidth = maxWidth; objNode.style.maxHeight = maxHeight; objNode.attributes.width.nodeValue = width; objNode.attributes.height.nodeValue = height; } ]]></script>; } 3. 建立Flash文件场景相关的类 package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFormat; //导入第2节中建立的类 import BrowserCanvas; [SWF(width="550", height="400", frameRate="30", backgroundColor="#000000")] public class ResizeSceneClass extends Sprite { private var canvas:BrowserCanvas; public function ResizeSceneClass () { //Set up the stage so we don't scale (you may not want to do this, depending on your desired goal) stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; canvas = new BrowserCanvas(stage); stage.addEventListener(MouseEvent.CLICK,randomSize); } private function randomSize(event:Event=null):void { canvas.width = String( Math.random()*500 + 200); canvas.height = String( Math.random()*500 + 200); } } } 4. 把ResizeSceneClass和第1节建立的Flash文件相关 到此完成展开阅读全文
咨信网温馨提示:1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。




Flash舞台随窗口大小动态调整.docx



实名认证













自信AI助手
















微信客服
客服QQ
发送邮件
意见反馈



链接地址:https://www.zixin.com.cn/doc/7588624.html