1021:在我的动作脚本复制函数定义 [英] 1021: Duplicate function definition in my action Script

查看:168
本文介绍了1021:在我的动作脚本复制函数定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个跟进我的previous问题(<一href="http://stackoverflow.com/questions/15994739/problems-scripting-multiple-buttonsnearly-identical-in-a-single-action-script">Problems脚本多个按钮(几乎相同)在一个单一的动作脚本)

This is a follow up to my previous question (Problems Scripting Multiple Buttons(nearly identical) in a single Action Script)

我想提出一个互动Flash项目......它已经有17个不同的场景......

I am making an interactive flash Project...It has has 17 Separate scenes ...

  • 简介场景
  • 在Main_序列
  • 在15个别主打歌网页 ......
  • Intro Scene
  • "Main_ Sequence"
  • 15 Individually title song pages ....

在哪里我的第一个问题是主序有15个按钮,我需要......我现在用的是下面的code将其链接到15个不同的场景......

Where my first issue is the "main sequence" has 15 Buttons and I need to link them to the 15 separate scenes ...I am using the following code...

    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序列:重复的函数定义。资料来源:功能mouseDownHandler(事件:MouseEvent)方法:无效{

when I run the sequence I get the following 15 errors All 1021: Duplicate function definition. Source : function mouseDownHandler(event:MouseEvent):void {

我试图改变 ..._ g.addEventListener(的MouseEvent.MOUSE_DOWN,mouseDownHandler); 来包括独特的#next每个DownHandler前) TD_g.addEventListener12(的MouseEvent.MOUSE_DOWN,mouseDownHandler1); ..我仍然得到15错误...

I tried changing the ..._g.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);to include a unique #next to each DownHandler ex) TD_g.addEventListener12(MouseEvent.MOUSE_DOWN, mouseDownHandler1);..I still get 15 errors...

谢谢!

PS ......我也找插入停止(); 地方在行动脚本,以便以后播放动画这个场景的人有机会浏览和点击,而不是直接跳到下一个场景的按钮!

P.S ...I am also looking to insert stop(); somewhere in that action script so that after the animation is played for this scene people have the opportunity to navigate and click the buttons instead of it "jumping" to the next scene!

推荐答案

我个人使用哈希映射/字典来处理名称/值对这样的preFER。 所以,你的code可以写成:

Personally I prefer using hash map/Dictionary to handle name/value pairs like these. So your code could be written as:

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]);
}

不过,这并不解决您的问题。错误说你有函数mouseDownHandler 定义别的地方在你的code。点击与编译器错误错误的线路,找到重复的code。评论它现在然后找出它为什么是复制/粘贴在首位,提高/修复。心连心

Still that doesn't solve your problem. The error says you have function mouseDownHandler defined somewhere else in your code. Click on the lines with the errors in compiler errors and find the duplicate code. Comment it for now then figure out why it was copy/pasted in the first place and improve/fix that. HTH

这篇关于1021:在我的动作脚本复制函数定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆