1. 程式人生 > >flash大小隨瀏覽器大小變化自動變化 flash全屏 swf大小自動適應瀏覽器視窗的變化

flash大小隨瀏覽器大小變化自動變化 flash全屏 swf大小自動適應瀏覽器視窗的變化

第一步:註釋掉flex專案中的詞句 //[SWF(width="1250",height="650",backgroundColor="0X00AAFF")]

As程式碼如下:呼叫AddEvent介面

package helper.fullScreen
{
	import com.pblabs.engine.PBE;
	import com.pblabs.rendering2D.ui.SceneView;
	
	import config.ConfigMcWH;
	import config.ConfigSceneMap;
	import config.ConfigVar;
	
	import controller.publicCreateScene.CC_CreateScene;
	import controller.publicHeroMove.CC_HeroMove;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.external.ExternalInterface;
	import flash.system.Capabilities;
	import flash.utils.Timer;

	public class CH_FullScreen
	{
		public function CH_FullScreen()
		{
		}
		
		private static var instanceVal:CH_FullScreen;
		public static function instance():CH_FullScreen
		{
			if(instanceVal==null)
			{
				instanceVal = new CH_FullScreen();
			}
			return instanceVal;
		}
		
		private var _sv:SceneView;
		private var _fun:Function;
		public function addAutoEvent(fun:Function=null):void
		{
			if(ConfigVar.screenIsAutoChange==true)
			{
				_fun = fun;
				PBE.mainStage.scaleMode=StageScaleMode.NO_SCALE;
				PBE.mainStage.align=StageAlign.TOP_LEFT;
				PBE.mainStage.addEventListener(Event.RESIZE, resizeDisplay2222);
			}
		}
		
		/**開啟和關閉全屏的介面*/
		private var nowIsFullScreen:Boolean = false;
		public function fullScreen():void
		{
			if(nowIsFullScreen==false)
			{
				PBE.mainStage.displayState = StageDisplayState.FULL_SCREEN;
				nowIsFullScreen = true;
			}else{
				PBE.mainStage.displayState = StageDisplayState.NORMAL;
				nowIsFullScreen = false;
			}
			resizeDisplay2222();
		}
		
		private function resizeDisplay2222(event:Event=null):void
		{
			if(event!=null)
			{
				trace(event.target.stageWidth+" ... "+event.currentTarget.stageWidth);
			}

			ConfigSceneMap.nowScreenSeeW = PBE.mainStage.stageWidth;
			ConfigSceneMap.nowScreenSeeH = PBE.mainStage.stageHeight;
			
			var logStr:String = "尺寸發生了變化----------------\n";
			if(event!=null)
			{
				logStr += "event.target : "+event.target.stageWidth+","+event.currentTarget.stageHeight;
			}
			logStr += "  PBE.mainStage : "+PBE.mainStage.stageWidth+","+PBE.mainStage.stageHeight;
			logStr += "  \nscreenSeeW : "+ConfigSceneMap.screenSeeW+","+ConfigSceneMap.screenSeeH;
			logStr += "  nowScreenSeeH : "+ConfigSceneMap.nowScreenSeeW+","+ConfigSceneMap.nowScreenSeeH;
			ConfigVar.logArr.push(logStr);

			/*
			ConfigSceneMap.nowScreenSeeW = (ConfigSceneMap.nowScreenSeeW <= 950) ? 950 : ConfigSceneMap.nowScreenSeeW;
			ConfigSceneMap.nowScreenSeeH = (ConfigSceneMap.nowScreenSeeH <= 560) ? 560 : ConfigSceneMap.nowScreenSeeH;
			
			ConfigSceneMap.nowScreenSeeW = (ConfigSceneMap.nowScreenSeeW >= 1250) ? 1250 : ConfigSceneMap.nowScreenSeeW;
			ConfigSceneMap.nowScreenSeeH = (ConfigSceneMap.nowScreenSeeH >= 650) ? 650 : ConfigSceneMap.nowScreenSeeH;
			*/
			changeFloatSp();
		}
		
		//改變所有浮動元素的位置
		private function changeFloatSp():void
		{
			ConfigVar.PUBLICMENUSP.x = ConfigSceneMap.nowScreenSeeW - ConfigMcWH.MENUWH.x;
			ConfigVar.PUBLICMENUSP.y = ConfigSceneMap.nowScreenSeeH - ConfigMcWH.MENUWH.y;
			
			ConfigVar.MENUTOSP.x = 5;
			ConfigVar.MENUTOSP.y = ConfigSceneMap.nowScreenSeeH - ConfigMcWH.CHATWH.y;
			/*
			if(ConfigVar.DIVSP.width>0 && ConfigVar.DIVSP.height>0)
			{
				trace(ConfigSceneMap.nowScreenSeeW+" aaaaaaaaa "+ConfigVar.DIVSP.width +","+ConfigVar.DIVSP.width);
				var folotDivSpW:int = ConfigVar.DIVSP.width;
				var folotDivSpH:int = ConfigVar.DIVSP.height;
				ConfigVar.DIVSP.x = (ConfigSceneMap.nowScreenSeeW - folotDivSpW)/2;
				ConfigVar.DIVSP.y = (ConfigSceneMap.nowScreenSeeH - folotDivSpH)/2;
				trace(ConfigVar.DIVSP.x+","+ConfigVar.DIVSP.y);
			}
			*/
			for(var i1:int=0,cnt1:int=ConfigVar.DIVSP.numChildren; i1<cnt1; i1++)
			{
				var obj1:* = ConfigVar.DIVSP.getChildAt(i1);
				if(obj1.visible==true)
				{
					trace(ConfigSceneMap.nowScreenSeeW+" aaaaaaaaa "+obj1.width +"  "+obj1.name);
					obj1.x = (ConfigSceneMap.nowScreenSeeW - obj1.width)/2;
					obj1.y = (ConfigSceneMap.nowScreenSeeH - obj1.height)/2;
				}
			}
			
		}
		
	}
}

第二步:改變swf檔案的html頁面
<html xmlns="http://www.w3.org/1999/xhtml"><head> 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>伍奇社群</title>
<script src="AC_OETags.js" language="javascript"></script>
<script language="javascript">
setTimeout("exchangePage();", 1000*4);
function exchangePage()
{
	var t1_obj = document.getElementById('t1');
	t1_obj.style.width = '100%';
	t1_obj.style.height = '100%';
}
</script>
<style>
*{margin:0px; padding:0px;}
body{
margin:0px auto;
overflow:auto;
background:#000000;
height:100%;
text-align: center;
}
#content{margin:0px auto; width:100%; height:100%; text-align:center;}
#t1{width:1px; height:1px;}
.temp{color:#FFF; font-size:14px; text-align:left; width:250px; margin:0px auto;}
</style>
</head>
<body>
<div style="width: 1250px; height: 650px; overflow:hidden; " id="content" align="center">
<div style="width: 1250px; height: 650px; overflow:hidden; " id="t1">
<script language="JavaScript" type="text/javascript">
var requiredMajorVersion = 10;
var requiredMinorVersion = 0;
var requiredRevision = 0;

var Config = {
        'service_url':  'http://www.92haowan.com/service/service',
        'bbs_url':      'http://bbs.92haowan.com/forum-112-1.html',
        'event_url':    'http://tt.92haowan.com/index/event',
        'home_url':     'http://tt.92haowan.com/',
        'save_url':     'http://tt.92haowan.com/',
        'vip_url':      'http://tt.92haowan.com/index/content/cid/115/id/724',
        'payment_url':  'http://www.92haowan.com/payment/payment/payment',
        'adult_check_url':      'http://www.92haowan.com/member/member/idcard'
};

function writeFlashObject(swf_src, param_str) 
{
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"100%\" height=\"100%\" id=\"wGame\" align=\"middle\"\>\n");
	document.write("<param name=\"allowScriptAccess\" value=\"always\" /\>\n");
	document.write("<param name=\"movie\" value=\""+ swf_src +"\" /\>\n");
	document.write("<param name=\"allowFullScreen\" value=\"true\" />");
	document.write("<param name=\"WMode\" value=\"Transparent\">");
	document.write("<param name=\"FlashVars\" value=\""+ param_str +"\" /\>\n");
	document.write("<param name=\"quality\" value=\"high\" /\>\n");
	document.write("<param name=\"bgcolor\" value=\"#000000\" /\>\n");
	document.write("<embed src=\""+ swf_src +"\" quality=\"high\" bgcolor=\"#000000\" width=\"100%\" height=\"100%\" name=\"wGame\" align=\"middle\" allowScriptAccess=\"always\" FlashVars=\""+ param_str +"\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /\>");
	document.write("</object\>");
}

//<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
// document.write("如果顯示了這段文字,那麼您的瀏覽器支援 JavaScript")
if ( hasProductInstall && !hasRequestedVersion ) {
	// DO NOT MODIFY THE FOLLOWING FOUR LINES
	// Location visited after installation is complete if installation is required
	var alternateContent = '<div class="temp"><p>您的flash版本過低,需要升級才能獲得更好的遊戲體驗。</p>'
		+'<p><b>#下載連結:</b></p>'
		+'<p><a href="http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player.exe">最新版</a></p>'
		+'<p><a href="http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_ax_debug.exe">最新版 (IE)</a></p>'
		+'<p><a href="http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_plugin_debug.exe">最新版 (非IE)</a></p>'
		+'<p>最新版Flash Player線上安裝:<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">IE</a>、<a href="http://www.adobe.com/shockwave/download/alternates/" target="_blank">非IE</a></p></div>';
	document.write(alternateContent);  // insert non-flash content
} else if (hasRequestedVersion) {
writeFlashObject("Main.swf?version=TianTu-1.6.0-r10859-release", "serid=9&res=http://ttcdn.92haowan.com/TianTu_release_r10885〈=zh_CN&web=http://tt4.92haowan.com&gateway=gateway.php&svrip=tt4.92haowan.com&svrport=39000&version=TianTu-1.6.0-r10859-release&auth_key=8b8a851cbec1351afa1a2ec48c40472f&service_url=http%3A%2F%2Fwww.92haowan.com%2Fservice%2Fservice&bbs_url=http%3A%2F%2Fbbs.92haowan.com%2Fforum-112-1.html&event_url=http%3A%2F%2Ftt.92haowan.com%2Findex%2Fevent&home_url=http%3A%2F%2Ftt.92haowan.com%2F&save_url=http%3A%2F%2Ftt.92haowan.com%2F&vip_url=http%3A%2F%2Ftt.92haowan.com%2Findex%2Fcontent%2Fcid%2F115%2Fid%2F724&payment_url=http%3A%2F%2Fwww.92haowan.com%2Fpayment%2Fpayment%2Fpayment&adult_check_url=http%3A%2F%2Fwww.92haowan.com%2Fmember%2Fmember%2Fidcard&guide_map_id=48&adult_mark=0")} else {  // flash is too old or we can't detect the plugin
	var alternateContent = '<div class="temp"><p>您還未安裝flash,請下載安裝後進行遊戲。</p>'
		+'<p><b>#下載連結:</b></p>'
		+'<p><a href="http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player.exe">最新版</a></p>'
		+'<p><a href="http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_ax_debug.exe">最新版 (IE)</a></p>'
		+'<p><a href="http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_plugin_debug.exe">最新版 (非IE)</a></p>'
		+'<p>最新版Flash Player線上安裝:<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">IE</a>、<a href="http://www.adobe.com/shockwave/download/alternates/" target="_blank">非IE</a></p></div>';
	document.write(alternateContent);  // insert non-flash content
}

// -->
</script><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" name="wGame" width="100%" height="100%" align="middle" id="wGame">
<param name="allowScriptAccess" value="always">
<param name="movie" value="Main.swf?version=TianTu-1.6.0-r10859-release">
<param name="FlashVars" value="serid=9&res=http://ttcdn.92haowan.com/TianTu_release_r10885&lang=zh_CN&web=http://tt4.92haowan.com&gateway=gateway.php&svrip=tt4.92haowan.com&svrport=39000&version=TianTu-1.6.0-r10859-release&auth_key=8b8a851cbec1351afa1a2ec48c40472f&service_url=http%3A%2F%2Fwww.92haowan.com%2Fservice%2Fservice&bbs_url=http%3A%2F%2Fbbs.92haowan.com%2Fforum-112-1.html&event_url=http%3A%2F%2Ftt.92haowan.com%2Findex%2Fevent&home_url=http%3A%2F%2Ftt.92haowan.com%2F&save_url=http%3A%2F%2Ftt.92haowan.com%2F&vip_url=http%3A%2F%2Ftt.92haowan.com%2Findex%2Fcontent%2Fcid%2F115%2Fid%2F724&payment_url=http%3A%2F%2Fwww.92haowan.com%2Fpayment%2Fpayment%2Fpayment&adult_check_url=http%3A%2F%2Fwww.92haowan.com%2Fmember%2Fmember%2Fidcard&guide_map_id=48&adult_mark=0">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<param name="allowFullScreen" value="true" />
<param name="WMode" value="Transparent">
<embed src="Main.swf" quality="high" bgcolor="#000000" name="wGame" allowscriptaccess="always" flashvars="serid=9&res=http://ttcdn.92haowan.com/TianTu_release_r10885&lang=zh_CN&web=http://tt4.92haowan.com&gateway=gateway.php&svrip=tt4.92haowan.com&svrport=39000&version=TianTu-1.6.0-r10859-release&auth_key=8b8a851cbec1351afa1a2ec48c40472f&service_url=http%3A%2F%2Fwww.92haowan.com%2Fservice%2Fservice&bbs_url=http%3A%2F%2Fbbs.92haowan.com%2Fforum-112-1.html&event_url=http%3A%2F%2Ftt.92haowan.com%2Findex%2Fevent&home_url=http%3A%2F%2Ftt.92haowan.com%2F&save_url=http%3A%2F%2Ftt.92haowan.com%2F&vip_url=http%3A%2F%2Ftt.92haowan.com%2Findex%2Fcontent%2Fcid%2F115%2Fid%2F724&payment_url=http%3A%2F%2Fwww.92haowan.com%2Fpayment%2Fpayment%2Fpayment&adult_check_url=http%3A%2F%2Fwww.92haowan.com%2Fmember%2Fmember%2Fidcard&guide_map_id=48&adult_mark=0" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="100%" align="middle" height="100%"></object>
</div>

<script language="javascript" type="text/javascript"> 
//flash視窗大小設定
function resizeBrowser()
{
var max_width = 1250;
var max_height= 650;
contentObj = document.getElementById('content');
var bodyWidth = (window.innerWidth) ? window.innerWidth : (document.body && document.body.clientWidth) ? document.body.clientWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth; 
var bodyHeight = (window.innerHeight) ? window.innerHeight : (document.body && document.body.clientHeight) ? document.body.clientHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight; 
if (bodyWidth > max_width) 
{
	contentObj.style.width = max_width + 'px';
}
else
{
	contentObj.style.width = '100%';
}
if (bodyHeight > max_height)
{
	contentObj.style.height = max_height + 'px';
}
else
{
	contentObj.style.height = '100%';
}
if (document.getElementById('wGame'))
{
	document.getElementById('wGame').focus();
}
}
resizeBrowser();
window.onresize=resizeBrowser;
</script>
<noscript>
您的的瀏覽器不支援JavaScript,請從開啟相關設定。
</noscript>
</div></body></html>


注意:1250*650 是自定義的flash最大的尺寸,完成上面操作後,你嵌入頁面的swf就會跟隨瀏覽器的大小變化而變化。就像遊戲 天途 的效果一樣。

相關推薦

flash大小瀏覽器大小變化自動變化 flash swf大小自動適應瀏覽器視窗變化

第一步:註釋掉flex專案中的詞句 //[SWF(width="1250",height="650",backgroundColor="0X00AAFF")] As程式碼如下:呼叫AddEvent介面 package helper.fullScreen { import

Qt QLabel 大小內容自動變化 && 內容填充整個label空間

技術 content () tco 分享 contents font nbsp com 圖1:label的本身大小 圖2:給label設置文字,不做任何別的設置 ui->label->setText(QObject::tr("current font

C#控制元件大小窗體大小等比例變化

C#控制元件大小隨窗體大小等比例變化 轉載自:http://www.knowsky.com/898409.html 相信很多博友在開發初次接觸學習C# winForm時,當窗體大小變化時,窗體內的控制元件並沒有隨著窗體的變化而變化,最近因為一個專案工程的原因,也需要解

echarts圖表初始大小問題及echarts視窗變化適應

不知道大家在用echarts的時候有沒有遇到這種情況:最開始盛放圖表的容器是隱藏(或者tab切換)的,然後再顯示的時候,裡面echarts圖表就沒用初始大小了。比如我遇到的這種: 有童鞋這會兒估計看出原因了:因為元素最初隱藏,再顯示之後沒有自動變化寬度,所

標籤(div、input)大小內容變化

1.div標籤隨內容大小變化 這些黃色矩形框大小得隨內容變化,適應性的 哈哈哈想一下,你會怎麼做? 其實很簡單 沒錯!width:auto;就可以了 咦,好像有點擠,沒事,加個padding: 10px; .blockcolors

控制元件大小視窗變化的方法(MFC)

形式1:用於在單文件視窗中,或者是手動建立的listctrl void CTrade_MISView::OnSize(UINT nType, int cx, int cy) {  CView::OnSize(nType, cx, cy);  // TODO: Add your message handl

js監聽視窗變化動態改變div大小

js監聽視窗變化動態改變div大小 function getHeight(val) { this.processHeight=(window.innerHeight || document.documentElement.clientHeigh)-210 +'px';

js頭部設定瀏覽器字型大小視窗大小而改變

<script> /* 長寬佔位 rem演算法, 根據root的rem來計算各元素相對rem, 預設html 320/20 = 16px */ /* 長寬佔位 rem演算法, 根據root的rem來計算各元素相對rem, 預設html 320/20 =

echarts 圖表大小視窗變動而自適應變動(無需重新整理瀏覽器調整)

var myChart = echarts.init(document.getElementById('main'));// 指定圖表的配置項和資料var option = {    title: {        text: 'ECharts 入門示例'    },    tooltip: {},    l

Flash適應瀏覽器螢幕大小的幾種方法

讓Flash自適應瀏覽器螢幕大小 作者:sutroon   型別:閃吧BBS   來源:閃吧個人空間   要讓flash自適應瀏覽器螢幕大小需要做到以下兩點: 1、swf檔案隨著瀏覽器螢幕大小也相應改變大下; 方法:在網頁裡除了放你的swf檔案外不要放其他的任何內容,並且

VISUAL C++根據父視窗變化調整控制元件大小

如果對話方塊或視類的大小調後,控制元件的大小和位置沒有變化,介面看起來會很不爽 控制元件是從CWnd派生的,但不能使用SetWindowPos()或OnSize()或OnSizing()來改變其大小,應在父視窗的WM_SIZE訊息中使用MoveWindow()

HTML中使背景圖片自適應瀏覽器大小

pub 拉伸 htm char html back 圖片 title tran 1、圖片不夠大,又background屬性不能拉伸圖片; 2、只能用個div,把其z-index值設為負,並使這個div大小為整個body大小,在div裏用<img> 3、b

html 網頁背景圖片根據大小CSS自動縮放

val apple back clas 交互 dde fun 效果 而且 https://blog.csdn.net/coslay/article/details/47109281 騰訊微博和QQ空間的登錄背景圖片是根據訪客的屏幕大小自動縮放的,但是好像是用JQuery代碼

彈窗居中,不會頁面滾動變化,直接固定在幕中央

tran ansi 彈窗 form nsf 直接 left 隨著 transform 定位top為50%;left為50%; 然後使用transifrom transform: translate(-50%, -50%); -webkit-transf

MFC 控制元件大小窗體改變而改變大小-OnSize

轉載:https://blog.csdn.net/zhoxier/article/details/7776128 一個基於對話方塊的MFC介面,怎麼樣才能讓對話方塊裡的控制元件能和對話方塊同比例變小變大?今天我一直想解決這個問題,這是師姐留給我的任務。經過在網上的大量搜

easyui中datagrid自適應瀏覽器大小

因為datagrid的fitColumns只有在初次載入資料的時候生效,所以在載入完資料後再改變瀏覽器大小,datagrid是不會改變大小的,只能保持在載入資料的時候的瀏覽器大小 解決方法就是動態設定fitColumns:true 這個有個弊端就是 只要改變瀏覽器大小就要重新載入,即走一遍後

新版本谷歌瀏覽器自動執行flash

煩死了這個玩意,所以百度搜了一下教程,很多都是老版本設定,很少有詳細的新版本解決方案。 記錄一下: 1.在谷歌瀏覽器上開啟chrome://flags/#enable-ephemeral-flash-permission 將其設定成 2.重啟瀏覽器 3.重啟瀏覽器後進入chr

如何設置谷歌瀏覽器自動啟動Flash

高級設置 -o f2c ffffff png proc 直接 谷歌瀏覽器 頁面滾動 很多人用谷歌瀏覽器的時候,chrome谷歌瀏覽器flash突然多了個懸浮播放按鈕,怎麽開啟Chrome谷歌瀏覽器flash插件,請看下面的方法。 打開谷歌瀏覽器 點擊右上角“三”字圖

VC中自動改變控制元件位置和大小的對話方塊類

lxDialog.h檔案: ///////////////////////////////////////////////////////////////////////////////////// // 自動改變控制元件位置和大小的對話方塊類 // 檔名:lxDialog.h //

【selenium3+JAVA】介面自動化測試教程(三)——瀏覽器、最大化和設定大小位置

1、瀏覽器全屏 使用程式碼如下: ChromeDriver chrome = new ChromeDriver(); chrome.manage().window().fullscreen(); 如上程式碼會把瀏覽器全屏,效果嘛就是除了網站的內容部分,其他全部