1

这是我之前的问题( Problems Scripting Multiple Buttons(nearlyly same) in a single Action Script)的后续问题

我正在制作一个交互式 Flash 项目......它有 17 个独立的场景......

  • 介绍场景
  • “主序列”
  • 15个单独的标题歌曲页面....

我的第一个问题是“主序列”有 15 个按钮,我需要将它们链接到 15 个单独的场景......我正在使用以下代码......

    TD_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    s_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    ats_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    iyk_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    hms_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    tf_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    hd_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    ld_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    ll_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    ts_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    ipsy_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    ysm_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    ihm_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    iss_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    tl_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    function mouseDownHandler(event:MouseEvent):void {
   var nameOfButton:String=event.currentTarget.name;
   if (nameOfButton=="TD_g") {
    gotoAndStop(1, "Tweedlee_Dee");
} else if (nameOfButton=="s_g") {
    gotoAndStop(1, "Sincerely");
} else if (nameOfButton=="ats_g") {
    gotoAndStop(1, "Ain’_that_a_shame");
} else if (nameOfButton=="iyk_g") {
    gotoAndStop(1, "I_hear_you_knocking");
} else if (nameOfButton=="hms_g") {
    gotoAndStop(1, "Hearts_made_of_stone");
} else if (nameOfButton=="tf_g") {
    gotoAndStop(1, "Tutti_fruiti");
} else if (nameOfButton=="hd_g") {
    gotoAndStop(1, "Hound_Dog");
} else if (nameOfButton=="ld_g") {
    gotoAndStop(1, "Little_darlin");
} else if (nameOfButton=="ll_g") {
    gotoAndStop(1, "Louie_Louie");
} else if (nameOfButton=="ts_g") {
    gotoAndStop(1, "Twist_and_shout");
} else if (nameOfButton=="ipsy_g") {
    gotoAndStop(1, "I_put_a_spell_on_you");
} else if (nameOfButton=="ysm_g") {
    gotoAndStop(1, "You_shook_me");

} else if (nameOfButton=="ihm_g") {
    gotoAndStop(1, "I_can_hear_music");

} else if (nameOfButton=="iss_g") {
    gotoAndStop(1, "I_shot_the_sheriff");

} else if (nameOfButton=="tl_g") {
    gotoAndStop(1, "Tainted_love");
}
    }

当我运行序列时,出现以下 15 个错误1021: Duplicate function definition. Source : function mouseDownHandler(event:MouseEvent):void {

我尝试将其更改为..._g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);在每个 DownHandler ex) 中包含一个唯一的#next) TD_g.addEventListener12(MouseEvent.MOUSE_DOWN, mouseDownHandler1);..我仍然收到 15 个错误...

谢谢 !

PS ...我还希望stop();在该动作脚本中插入某个位置,以便在为该场景播放动画后,人们有机会导航并单击按钮,而不是“跳转”到下一个场景!

4

1 回答 1

0

我个人更喜欢使用哈希映射/字典来处理这样的名称/值对。所以你的代码可以写成:

var buttonMap:Dictionary = new Dictionary();
buttonMap["TD_g"] = "Tweedlee_Dee";
buttonMap["s_g"] = "Sincerely";
buttonMap["ats_g"] = "Ain’_that_a_shame";
buttonMap["iyk_g"] = "I_hear_you_knocking";
buttonMap["hms_g"] = "Hearts_made_of_stone";
buttonMap["tf_g"] = "Tutti_fruiti";
buttonMap["hd_g"] = "Hound_Dog";
buttonMap["ld_g"] = "Little_darlin";
buttonMap["ll_g"] = "Louie_Louie";
buttonMap["ts_g"] = "Twist_and_shout";
buttonMap["ipsy_g"] = "I_put_a_spell_on_you";
buttonMap["ysm_g"] = "You_shook_me";
buttonMap["ihm_g"] = "I_can_hear_music";
buttonMap["iss_g"] = "I_shot_the_sheriff";
buttonMap["tl_g"] = "Tainted_love";

TD_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
s_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ats_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
iyk_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
hms_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
tf_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
hd_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ld_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ll_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ts_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ipsy_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ysm_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
ihm_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
iss_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
tl_g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

function mouseDownHandler(event:MouseEvent):void {
    gotoAndStop(1, buttonMap[event.currentTarget.name]);
}

仍然不能解决你的问题。该错误表明您已function mouseDownHandler在代码中的其他位置定义。单击编译器错误中带有错误的行并找到重复的代码。暂时评论它,然后弄清楚为什么它首先被复制/粘贴并改进/修复它。高温高压

于 2013-04-14T18:30:59.197 回答