AS3-控制时间线的按钮在 MovieClip 中不起作用
这是我第一次使用 ActionScript 编写网站。到目前为止一切都很顺利,我在Photoshop中设计了网站,并导入到Flash CS5中。然后我清理了所有内容,并开始使用按钮向各个页面添加导航。
该网站的构建方式非常简单,有五个主要页面,它们通过静态导航栏上的按钮连接(第一页,主页,没有相应的按钮)。然后有九个子页面,每个子页面包含游戏角色的信息,并连接到“角色”层/电影剪辑中的相应按钮。我的四个菜单按钮(故事、世界、角色、附加)都可以正确导航,没有任何问题。
出现问题是因为我的角色页面(影片剪辑)中有九个按钮,每个按钮都链接到不同的页面。这些按钮应该将时间线带到指定的帧,但是单击按钮时什么也没有发生。我花了几个小时寻找解决方案,但没有结果,而且我感觉答案很简单。你觉得你能帮我吗?
这是我到目前为止所尝试过的:
替换
gotoAndStop("gowang", "Scene 1");
将Gowang 字符按钮功能中的行
MovieClip(root).gotoAndStop("gowang");
为:但这产生了相同的结果,按钮什么也不做。
我还尝试将角色按钮侦听器和函数放置在角色页面 MovieClip 中,但这给了我这个错误:
ArgumentError: Error #2108: Scene Scene 1 was not found.
在 flash.display::MovieClip/gotoAndStop()
在 Gowang_fla::Top_31/clickGowang()
我花了很多时间试图解决这个问题,如果有人可以提供帮助,我将非常感激。
~这里是 .FLA: http://mindsparkdesigns.com/files/WebsiteFla.zip
~这是代码:
stop();
//Fade Effect
import fl.transitions.Tween;
import fl.transitions.easing.*;
var homeTween:Tween = new Tween(home_mc, "alpha", Regular.easeOut , 0, 1, 2, true);
//Buttons
story_btn.addEventListener(MouseEvent.CLICK, clickStory);
world_btn.addEventListener(MouseEvent.CLICK, clickWorld);
characters_btn.addEventListener(MouseEvent.CLICK, clickCharacters);
extras_btn.addEventListener(MouseEvent.CLICK, clickExtras);
home_mc.storyH_btn.addEventListener(MouseEvent.CLICK, clickStoryH);
home_mc.worldH_btn.addEventListener(MouseEvent.CLICK, clickWorldH);
home_mc.charactersH_btn.addEventListener(MouseEvent.CLICK, clickCharactersH);
home_mc.extrasH_btn.addEventListener(MouseEvent.CLICK, clickExtrasH);
top_mc.gowang_btn.addEventListener(MouseEvent.CLICK, clickGowang);
top_mc.ayame_btn.addEventListener(MouseEvent.CLICK, clickAyame);
top_mc.evora_btn.addEventListener(MouseEvent.CLICK, clickEvora);
top_mc.rogin_btn.addEventListener(MouseEvent.CLICK, clickRogin);
top_mc.toraz_btn.addEventListener(MouseEvent.CLICK, clickToraz);
top_mc.naomi_btn.addEventListener(MouseEvent.CLICK, clickNaomi);
top_mc.rummy_btn.addEventListener(MouseEvent.CLICK, clickRummy);
top_mc.teeth_btn.addEventListener(MouseEvent.CLICK, clickTeeth);
top_mc.sichan_btn.addEventListener(MouseEvent.CLICK, clickSichan);
extras_mc.blog_btn.addEventListener(MouseEvent.CLICK, clickBlog);
function clickBlog(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.gowangadventures.blogspot.com"), "_blank");
}
function clickGowang(evtObj:MouseEvent){
gotoAndStop("gowang", "Scene 1");
}
function clickAyame(evtObj:MouseEvent){
gotoAndStop("ayame", "Scene 1");
}
function clickEvora(evtObj:MouseEvent){
gotoAndStop("evora", "Scene 1");
}
function clickRogin(evtObj:MouseEvent){
gotoAndStop("rogin", "Scene 1");
}
function clickToraz(evtObj:MouseEvent){
gotoAndStop("toraz", "Scene 1");
}
function clickNaomi(evtObj:MouseEvent){
gotoAndStop("naomi", "Scene 1");
}
function clickRummy(evtObj:MouseEvent){
gotoAndStop("rummy", "Scene 1");
}
function clickTeeth(evtObj:MouseEvent){
gotoAndStop("teeth", "Scene 1");
}
function clickSichan(evtObj:MouseEvent){
gotoAndStop("sichan", "Scene 1");
}
function clickStory(evtObj:MouseEvent){
gotoAndStop("story");
}
function clickWorld(evtObj:MouseEvent){
gotoAndStop("world");
}
function clickCharacters(evtObj:MouseEvent){
gotoAndStop("characters");
}
function clickExtras(evtObj:MouseEvent){
gotoAndStop("extras");
}
function clickStoryH(evtObj:MouseEvent){
gotoAndStop("story", "Scene 1");
}
function clickWorldH(evtObj:MouseEvent){
gotoAndStop("world", "Scene 1");
}
function clickCharactersH(evtObj:MouseEvent){
gotoAndStop("characters", "Scene 1");
}
function clickExtrasH(evtObj:MouseEvent){
gotoAndStop("extras", "Scene 1");
}
This is my first time coding a website using ActionScript. So far everything has went very well, I designed the website in Photoshop, and imported to Flash CS5. Then I cleaned everything up, and started adding navigation to the various pages using buttons.
The website is constructed in a very simple manner, there are five main pages and they are connected by buttons on a static navigation bar (the first page, home, doesn't have a corresponding button). Then there are nine sub pages, that each contain information on a character of the game, and are connected to corresponding buttons in the 'Character' layer/MovieClip. My four menu buttons (Story, The World, Characters, Extras) all navigate correctly without problems.
The problem arises because inside my Characters page (a movie clip) are nine buttons, each linking to a different page. These buttons should bring the timeline to the frame specified, but when the buttons are clicked nothing happens. I've spent hours searching for a solution to this, but with no avail, and I have a feeling the answer is pretty simple. Think you could help me out?
Here is what i've tried so far:
Replacing the
gotoAndStop("gowang", "Scene 1");
line in the Gowang character button function with:
MovieClip(root).gotoAndStop("gowang");
But this produced the same result, the buttons doing nothing.
I've also tried placing the character button listeners and functions inside the Character page MovieClip, but that gave me this error:
ArgumentError: Error #2108: Scene Scene 1 was not found.
at flash.display::MovieClip/gotoAndStop()
at Gowang_fla::Top_31/clickGowang()
I've spent a lot of time trying to fix this one, and I would really appreciate if someone could help.
~Here is the .FLA: http://mindsparkdesigns.com/files/WebsiteFla.zip
~Here is the code:
stop();
//Fade Effect
import fl.transitions.Tween;
import fl.transitions.easing.*;
var homeTween:Tween = new Tween(home_mc, "alpha", Regular.easeOut , 0, 1, 2, true);
//Buttons
story_btn.addEventListener(MouseEvent.CLICK, clickStory);
world_btn.addEventListener(MouseEvent.CLICK, clickWorld);
characters_btn.addEventListener(MouseEvent.CLICK, clickCharacters);
extras_btn.addEventListener(MouseEvent.CLICK, clickExtras);
home_mc.storyH_btn.addEventListener(MouseEvent.CLICK, clickStoryH);
home_mc.worldH_btn.addEventListener(MouseEvent.CLICK, clickWorldH);
home_mc.charactersH_btn.addEventListener(MouseEvent.CLICK, clickCharactersH);
home_mc.extrasH_btn.addEventListener(MouseEvent.CLICK, clickExtrasH);
top_mc.gowang_btn.addEventListener(MouseEvent.CLICK, clickGowang);
top_mc.ayame_btn.addEventListener(MouseEvent.CLICK, clickAyame);
top_mc.evora_btn.addEventListener(MouseEvent.CLICK, clickEvora);
top_mc.rogin_btn.addEventListener(MouseEvent.CLICK, clickRogin);
top_mc.toraz_btn.addEventListener(MouseEvent.CLICK, clickToraz);
top_mc.naomi_btn.addEventListener(MouseEvent.CLICK, clickNaomi);
top_mc.rummy_btn.addEventListener(MouseEvent.CLICK, clickRummy);
top_mc.teeth_btn.addEventListener(MouseEvent.CLICK, clickTeeth);
top_mc.sichan_btn.addEventListener(MouseEvent.CLICK, clickSichan);
extras_mc.blog_btn.addEventListener(MouseEvent.CLICK, clickBlog);
function clickBlog(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.gowangadventures.blogspot.com"), "_blank");
}
function clickGowang(evtObj:MouseEvent){
gotoAndStop("gowang", "Scene 1");
}
function clickAyame(evtObj:MouseEvent){
gotoAndStop("ayame", "Scene 1");
}
function clickEvora(evtObj:MouseEvent){
gotoAndStop("evora", "Scene 1");
}
function clickRogin(evtObj:MouseEvent){
gotoAndStop("rogin", "Scene 1");
}
function clickToraz(evtObj:MouseEvent){
gotoAndStop("toraz", "Scene 1");
}
function clickNaomi(evtObj:MouseEvent){
gotoAndStop("naomi", "Scene 1");
}
function clickRummy(evtObj:MouseEvent){
gotoAndStop("rummy", "Scene 1");
}
function clickTeeth(evtObj:MouseEvent){
gotoAndStop("teeth", "Scene 1");
}
function clickSichan(evtObj:MouseEvent){
gotoAndStop("sichan", "Scene 1");
}
function clickStory(evtObj:MouseEvent){
gotoAndStop("story");
}
function clickWorld(evtObj:MouseEvent){
gotoAndStop("world");
}
function clickCharacters(evtObj:MouseEvent){
gotoAndStop("characters");
}
function clickExtras(evtObj:MouseEvent){
gotoAndStop("extras");
}
function clickStoryH(evtObj:MouseEvent){
gotoAndStop("story", "Scene 1");
}
function clickWorldH(evtObj:MouseEvent){
gotoAndStop("world", "Scene 1");
}
function clickCharactersH(evtObj:MouseEvent){
gotoAndStop("characters", "Scene 1");
}
function clickExtrasH(evtObj:MouseEvent){
gotoAndStop("extras", "Scene 1");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在将按钮侦听器分配给声明它们时不在舞台上的按钮。将此代码移到第 30 帧上的补间代码下方,它应该可以工作:
由于您的“characters_mc”在该帧的舞台上,因此它们可以接受这些侦听器(因为当您之前尝试声明它们时它们不存在) 。
It looks like you're assigning button listeners to buttons that aren't on the stage at the point you're declaring them. Move this code below your tween code on frame 30 and it should work:
Since your 'characters_mc' is on the stage at that frame, they're available to accept those listeners (since they didn't exist when you tried declaring them before).
您可以使用
MovieClip
作为按钮:You can use
MovieClip
as a button: