1.7 下面可以写代码了,这次跳转,我会让相应的page定位至mask那里,从而让该页面显示,其它则隐藏。
主场景的帧里写:
var initx = mask._x;//首先定位一个初始点,这是页面定位的常量
var inity = mask._y;//同上
var targetx=initx;
var targety=inity;//这两个变量也用于定位,使用韩式缓冲公式算法,可以让MC缓慢地移动到(targetx,targety)这一点。
this.onEnterFrame = function() {
pages._x = pages._x-0.2*(pages._x-pages.targetx);
pages._y = pages._y-0.2*(pages._y-pages.targety);
};//这个则是缓冲公式
function loadNews(href) {//定义按钮触发的函数
pages.targetx = initx-pages[href]._x;
pages.targety = inity-pages[href]._y;//先让target定位至当前MC(也就是传入的参数href),然后缓冲公式会让当前传入的MC显示出来,其它的则隐藏
fscommand("setAddress", href);//设定地址栏内容,用于刷新页面时的定位,在JS里会响应这一命令。
getURL("statistics.html?"+href, "stat");//打开iframe,让iframe记录当前点到的MC的实例名href
}
2.1 以带有fscommand跟踪的Flash发布一个HTML文件和一个SWF文件,接着把发布设置中格式选项卡的HTML勾去掉。
2.2 用记事本打开index_flash.html文件,找到//place your code here 一句。写入
if(command=="setAddress"){
document.location.hash=args
}
2.3 然后定义一个onLoad执行的函数JS_LoadNews
function JS_LoadNews(){
window.open("statistics.html?"+document.location.hash.slice(1),"stat")//让名为stat的iframe打开一个带参数的地址
}
2.4 根据上一步的JS,加一个iframe
<iframe noscroll border="0" src="about:blank" width="1" height="1" name="stat" id="stat"></iframe>
2.5 在body标签里加onload=JS_LoadNews()
3.1 新建一个HTML文件,名为statistics.html,在这里写入控制Flash的代码:
<script language="javascript">
function pageLoad(){
window.parent.index_flash.setVariable("link",window.document.location.search.slice(1))//parent指父级框架,这里可以指向FLASH文件,location.search是获取地址参数,该值包含“?”,所以用slice(1)去掉。
}
</script>
<body onload=pageLoad()>
</body>
3.2 上面的代码设置了Flash里的link值,为了触发Flash的函数,在Flash里用addProperty来触发相关函数:
追加帧代码:
this.addProperty("link", getLink, setLink);
function getLink() {
}
function setLink(link) {
fscommand("setAddress", link);
pages.targetx = initx-pages[link]._x;
pages.targety = inity-pages[link]._y;
}
此文章共有2页 1 2