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.οnresize=resizeBrowser;
</script>
<noscript>
您的的瀏覽器不支持JavaScript,請從打開相關設置。
</noscript>
</div></body></html>


注意:1250*650 是自定義的flash最大的尺寸,完成上面操作後,你嵌入頁面的swf就會跟隨瀏覽器的大小變化而變化。就像遊戲 天途 的效果一樣。
發佈了29 篇原創文章 · 獲贊 11 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章