Flash舞台随窗口大小动态调整
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//Check if we have an embed tag inside of us, if so, ignore the obj tag
if (this.containerId == null) this.containerId = ExternalInterface.objectID;
if (this.containerId == null) this.containerId = ExternalInterface.call(JSScripts.GET_FLASH_ID, stage.loaderInfo.url);
trace("BrowserCanvas - Copyright (c) 2008 Noel Billig ()");
this.stage = stage;
timerSprite = new Sprite();
_width = String( stage.stageWidth );
(erAgent.toLowerCase().indexOf("opera") != -1)) &&
(objNode.nodeName.toLowerCase() == "object") &&
(browserHacks.indexOf("uniqueId") != -1)
) {ห้องสมุดไป่ตู้
return fileName;
}
var ensureId = function(node) {
if (node.attributes["id"] == null) {
node.setAttribute("id",'swf'+new Date().getTime());
}
}
var matchesTarget = function(fullPath) {
if (browserHacks.length != 0) {
this.containerId = ExternalInterface.call(JSScripts.INSERT_BROWSER_HACKS, this.containerId, browserHacks.join(","));
}
}
public function set width(newWidth:String):void {
this._height = formatSize(newHeight);
invalidate();
}
public function set minHeight(newHeight:String):void {
this._minHeight = formatSize(newHeight);
invalidate();
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;
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"
//If you make the mistake of naming the object and embed nodes with the same id, firefox will get confused
if (((erAgent.toLowerCase().indexOf("firefox") != -1) ||
ExternalInterface.call(JSScripts.RESIZE_CONTAINER,containerId,_width,_height,_minWidth,_minHeight,_maxWidth,_maxHeight);
}
}
}
class JSScripts {
public static var GET_FLASH_ID:XML =
var paramNodes = nodes[j].getElementsByTagName("param");
for (var k=0; k < paramNodes.length; k++) {
if (paramNodes[k].attributes["name"].nodeValue.toLowerCase() == "movie") {
}
public function set maxHeight(newHeight:String):void {
this._maxHeight = formatSize(newHeight);
invalidate();
}
private function formatSize(size:String):String {
}
public function set maxWidth(newWidth:String):void {
this._maxWidth = formatSize(newWidth);
invalidate();
}
public function set height(newHeight:String):void {
_height = String( stage.stageHeight );
if (browserHacks == null) browserHacks = [HACK_MARGIN_BOTTOM,HACK_IE_REPARENT,HACK_UNIQUE_ID];
this.containerId = containerId;
return (getFileName(fullPath) == targetSwfName);
}
var targetSwfName = getFileName(swfFullPath);
//Look through the embed nodes for one that matches our swf name
if (size == null) return ""; //Null causes opera to never clear the appropriate values, so use empty string
return (int(size) == 0) ? size : size+"px";
<script><![CDATA[
function(swfFullPath) {
var getFileName = function(fullPath) {
var ary = fullPath.split("/");
var fileName = ary[ary.length-1].split(".swf")[0];
public static var INSERT_BROWSER_HACKS:XML =
<script><![CDATA[
function (containerId,browserHacks) {
var objNode = document.getElementById(containerId);
if (objNode.nodeName.toLowerCase() == "div") return;
}
private function invalidate():void {
timerSprite.addEventListener(Event.ENTER_FRAME,update);
}
private function update(event:Event):void {
timerSprite.removeEventListener(Event.ENTER_FRAME,update);
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[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
this._width = formatSize(newWidth);
invalidate();
}
public function set minWidth(newWidth:String):void {
this._minWidth = formatSize(newWidth);
invalidate();
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
private var _maxHeight:String;
private var timerSprite:Sprite;
publicfunction BrowserCanvas(stage:Stage,containerId:String=null,browserHacks:Array=null){
if (matchesTarget(paramNodes[k].attributes["value"].nodeValue)) {
ensureId(nodes[j]);
return nodes[j].attributes["id"].nodeValue;
}
}
}
}
return null;
}
]]></script>;
本文介绍如何建立一个舞台随窗体尺寸大小动态改变的Flash例子,使用的脚本为AS3.0
1.建立工程
2.新建一个AS文件,主要实现舞台的动态缩放功能
代码如下:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
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
private var containerId:String;
private var _width:String;
private var _minWidth:String;
private var _maxWidth:String;
private var _height:String;
private var _minHeight:String;
if (this.containerId == null) this.containerId = ExternalInterface.objectID;
if (this.containerId == null) this.containerId = ExternalInterface.call(JSScripts.GET_FLASH_ID, stage.loaderInfo.url);
trace("BrowserCanvas - Copyright (c) 2008 Noel Billig ()");
this.stage = stage;
timerSprite = new Sprite();
_width = String( stage.stageWidth );
(erAgent.toLowerCase().indexOf("opera") != -1)) &&
(objNode.nodeName.toLowerCase() == "object") &&
(browserHacks.indexOf("uniqueId") != -1)
) {ห้องสมุดไป่ตู้
return fileName;
}
var ensureId = function(node) {
if (node.attributes["id"] == null) {
node.setAttribute("id",'swf'+new Date().getTime());
}
}
var matchesTarget = function(fullPath) {
if (browserHacks.length != 0) {
this.containerId = ExternalInterface.call(JSScripts.INSERT_BROWSER_HACKS, this.containerId, browserHacks.join(","));
}
}
public function set width(newWidth:String):void {
this._height = formatSize(newHeight);
invalidate();
}
public function set minHeight(newHeight:String):void {
this._minHeight = formatSize(newHeight);
invalidate();
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;
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"
//If you make the mistake of naming the object and embed nodes with the same id, firefox will get confused
if (((erAgent.toLowerCase().indexOf("firefox") != -1) ||
ExternalInterface.call(JSScripts.RESIZE_CONTAINER,containerId,_width,_height,_minWidth,_minHeight,_maxWidth,_maxHeight);
}
}
}
class JSScripts {
public static var GET_FLASH_ID:XML =
var paramNodes = nodes[j].getElementsByTagName("param");
for (var k=0; k < paramNodes.length; k++) {
if (paramNodes[k].attributes["name"].nodeValue.toLowerCase() == "movie") {
}
public function set maxHeight(newHeight:String):void {
this._maxHeight = formatSize(newHeight);
invalidate();
}
private function formatSize(size:String):String {
}
public function set maxWidth(newWidth:String):void {
this._maxWidth = formatSize(newWidth);
invalidate();
}
public function set height(newHeight:String):void {
_height = String( stage.stageHeight );
if (browserHacks == null) browserHacks = [HACK_MARGIN_BOTTOM,HACK_IE_REPARENT,HACK_UNIQUE_ID];
this.containerId = containerId;
return (getFileName(fullPath) == targetSwfName);
}
var targetSwfName = getFileName(swfFullPath);
//Look through the embed nodes for one that matches our swf name
if (size == null) return ""; //Null causes opera to never clear the appropriate values, so use empty string
return (int(size) == 0) ? size : size+"px";
<script><![CDATA[
function(swfFullPath) {
var getFileName = function(fullPath) {
var ary = fullPath.split("/");
var fileName = ary[ary.length-1].split(".swf")[0];
public static var INSERT_BROWSER_HACKS:XML =
<script><![CDATA[
function (containerId,browserHacks) {
var objNode = document.getElementById(containerId);
if (objNode.nodeName.toLowerCase() == "div") return;
}
private function invalidate():void {
timerSprite.addEventListener(Event.ENTER_FRAME,update);
}
private function update(event:Event):void {
timerSprite.removeEventListener(Event.ENTER_FRAME,update);
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[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
this._width = formatSize(newWidth);
invalidate();
}
public function set minWidth(newWidth:String):void {
this._minWidth = formatSize(newWidth);
invalidate();
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
private var _maxHeight:String;
private var timerSprite:Sprite;
publicfunction BrowserCanvas(stage:Stage,containerId:String=null,browserHacks:Array=null){
if (matchesTarget(paramNodes[k].attributes["value"].nodeValue)) {
ensureId(nodes[j]);
return nodes[j].attributes["id"].nodeValue;
}
}
}
}
return null;
}
]]></script>;
本文介绍如何建立一个舞台随窗体尺寸大小动态改变的Flash例子,使用的脚本为AS3.0
1.建立工程
2.新建一个AS文件,主要实现舞台的动态缩放功能
代码如下:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
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
private var containerId:String;
private var _width:String;
private var _minWidth:String;
private var _maxWidth:String;
private var _height:String;
private var _minHeight:String;