1021:我的动作脚本中的重复功能定义

时间:2013-04-14 15:09:37

标签: actionscript-3 flash actionscript flash-cs5 flash-cs4

这是对我之前的问题(Problems Scripting Multiple Buttons(nearly identical) in a single Action Script

的跟进

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

  • 介绍场景
  • " Main_ Sequence"
  • 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 TD_g.addEventListener12(MouseEvent.MOUSE_DOWN, mouseDownHandler1);中包含唯一的#next ..我仍然会收到15个错误...

谢谢!

PS ...我也希望在该动作脚本中的某处插入stop();,以便在为此场景播放动画后,人们有机会导航并单击按钮而不是它#34;跳跃"到下一个场景!

1 个答案:

答案 0 :(得分: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。单击包含编译器错误错误的行并找到重复的代码。现在评论然后找出为什么它首先被复制/粘贴并改进/修复它。 HTH