问题脚本多个按钮(几乎相同)在一个单一的动作脚本 [英] Problems Scripting Multiple Buttons(nearly identical) in a single Action Script

查看:172
本文介绍了问题脚本多个按钮(几乎相同)在一个单一的动作脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个小白行动脚本3,所以请原谅这个详细的发布! (和code发布错误)

I am a noob to action script 3 so please forgive this detailed Posting ! (and code posting errors)

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

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

  • 简介场景
  • 在Main_序列
  • 在15个别主打歌页

我已经脚本的介绍 - >主序列,没有任何问题......

I have scripted the Intro-->"main" sequence with no problems ....

在哪里我的问题是主序有15个按钮和我需要将它们链接到15个不同的场景......我已经尝试了两套不同的code(见下文),并不断得到编译器错误... ..我将AP preciate如果有一个人能告诉我,这两种格式这是最适合我的目的和放大器;究竟我做错了......

Where my issue is the "main sequence" has 15 Buttons and I need to link them to the 15 separate scenes ...I have tried two different sets of code(see below) and kept getting Compiler Errors... ..I would appreciate if some one can tell me which of these two formats is best for my purpose & what exactly I am doing wrong ....

code 1:这是一个从我使用什么样的个人网页链接回主序修改

Code 1: This is a modified from what I am using to link the individual pages back to the main sequence

TD_g.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler1);
function mouseDownHandler1(event:MouseEvent):void {

gotoAndStop(1,"Tweedlee_Dee");
}
  s_g.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {

gotoAndStop(1,"Sincerely");
}
      ats_g.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler3);
  function mouseDownHandler3(event:MouseEvent):void {

gotoAndStop(1,"Ain’_that_a_shame");

......重复15次......的 _G 部分是在参考了独特的实例名称我分配到每个按钮上主序...​​...我改变了中的每个 MouseDownHandlr ,因为我读的地方,每一个事件必须是不同的( ?) ..Every一次我考我碰到下面的一幕......

...Repeated 15 times ... the _gportion is in reference to the unique instance names I assigned to each button on the main sequence ...I changed the #in each MouseDownHandlrbecause I read somewhere that each event had to be different(?) ..Every time I test the scene I get the following ...

类型错误:错误#1009:无法访问空对象引用的属性或方法。     在music_Sheet_project_14_Main_Sequence_fla :: MainTimeline /帧1(......然后现场即开始并执行它的动画其次是鼠标悬停的影响,但它应该会返回一个错误(?)的按钮,如果我点击它们不产生反应

TypeError: Error #1009: Cannot access a property or method of a null object reference. at music_Sheet_project_14_Main_Sequence_fla::MainTimeline/frame1( ...and then the scene starts as and does its animation followed by the mouseover effects but the buttons which should return an error(?) if I click on them produce no "reaction"

......每次我测试影片(只有这短短的code!)我得到以下...

...everytime I test the movie(with just that short code!) I get the following ...

14的编译器错误

所有1021:重复的函数定义来源:函数mouseDownHandler(事件:MouseEvent)方法:无效{

** code2 **这是一个不同的code,我发现我的风格时发现试图解决的第一个code

**Code2 **This is a different code I found style I found while trying to fix the first code

stop();
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");
}

...这样下去15多次,包括线路#64

{
else if (nameOfButton=="ysm_g");
{
 gotoAndStop(1, "You_shook_me");

当我尝试运行此我得到以下...

when I attempt to run this I get the following ...

。1083:语法错误:别人是意外源代码否则,如果(nameOfButton ==ysm_g);

当我看到这件事,我得到的建议是,语法是错误的...但为什么会选择这行,而不是所有的其他行......我试图重新输入和重新格式化,但我不断收到这个错误..

When I look this up I get suggestions that the syntax is wrong ...but why would it pick this line and not all the other lines...I have tried retyping and re formating but I keep getting that error...

*的以下哪项codeS是最好用的? (和为什么它不工作???) 任何/所有建议和放大器;帮助将大大pciated AP $ P $ ...谢谢! *

*Which of these codes is the Best to use ? (and why is it not working???) Any/All Advice & Help would greatly be appreciated ...THANKS!!! *

推荐答案

现在的问题是,你没有别的语句之前相应的右大括号。此外,你有分号在其他的到底哪个会搞乱了:

The problem is that you don't have a corresponding closing brace before the else statement. Additionally you have semi-colon at the end of the else which will mess things up:

{
else if (nameOfButton=="ysm_g");
{
 gotoAndStop(1, "You_shook_me");

{
//...Whatever code goes here
}
else if (nameOfButton=="ysm_g")
{
   gotoAndStop(1, "You_shook_me");
}

这篇关于问题脚本多个按钮(几乎相同)在一个单一的动作脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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