我在flash中做了三個選單,底下有一個bar會滑動,我的滑鼠移動到哪一個選單,bar就會移到那個選單。
接著,我想把這個選單放到網頁上使用,當頁面在第一頁時,bar在選單1,在第二頁時,bar是停在選單二,在第二頁時,bar是停在選單二。
我在html中先設好參數,接著再flash中利用此參數來改變停留頁面的狀態。
效果:
http://mcr.tw/stu/gjun/carino/index'.html
http://mcr.tw/stu/gjun/carino/aboutus.html
http://mcr.tw/stu/gjun/carino/contact.html
方法:
html檔中:
<body>
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="300" height="80">
<param name="flashvars" value="p=1" />
<param name="movie" value="menu.swf" />
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="105.0.0.0" />
<!-- 此 param 標籤會提示使用 Flash Player 6.0 r65 和更新版本的使用者下載最新版本的 Flash Player。如果您不想讓使用者看到這項提示,請將其刪除。 -->
<!--<param name="expressinstall" value="Scripts/expressInstall.swf" /> -->
<!-- 下一個物件標籤僅供非 IE 瀏覽器使用。因此,請使用 IECC 將其自 IE 隱藏。 -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="menu.swf" width="300" height="80">
<!--<![endif]-->
<param name="flashvars" value="p=1" />
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="105.0.0.0" />
<!--<param name="expressinstall" value="Scripts/expressInstall.swf" /> -->
<!-- 瀏覽器會為使用 Flash Player 6.0 和更早版本的使用者顯示下列替代內容。 -->
<div>
<h4>這個頁面上的內容需要較新版本的 Adobe Flash Player。</h4>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="取得 Adobe Flash Player" width="112" height="33" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
<script type="text/javascript">
swfobject.registerObject("FlashID");
</script>
</body>
flash actionscript3:
import com.greensock.TweenMax;
import flash.net.URLRequest;
var i:int;
var p:int = root.loaderInfo.parameters["p"];//取得HTML中的參數
var path:URLRequest = new URLRequest ;
bar.x = (p - 1) * 100;//選單底下的bar隨XML中的參數而改變
for (i=1; i<=3; i++)
{
this["m" + i].buttonMode = true;
this["m" + i].addEventListener(MouseEvent.MOUSE_OVER,_OVER);
this["m" + i].addEventListener(MouseEvent.MOUSE_OUT,_OUT);
this["m" + i].addEventListener(MouseEvent.CLICK,_CLICK);
}
function _OVER(e:MouseEvent)
{
TweenMax.to(bar,0.5,{x:(e.currentTarget.name.substr(1,1)-1)*100});
}
function _OUT(e:MouseEvent)
{
TweenMax.to(bar,0.5,{x:(p - 1) * 100});//選單底下的bar會隨的滑鼠滑出選單而滑回此頁面的選單
}
//////////////////點擊選單連結網頁//////////
function _CLICK(e:MouseEvent)
{
switch (e.currentTarget.name)
{
case "m1" :
path.url = "index.html";
break;
case "m2" :
path.url = "aboutus.html";
break;
case "m3" :
path.url = "contact.html";
break;
}
navigateToURL(path,"_self");
}
/////////////////////////////////////////////