开发者

Just Started in Flash CS4 - AS3 fallen over at first hurdle?

1). Wrote this simple code for a pic gallery tutorial to help me understand AS3:

//////Button1//////
thumb1_btn.addEventListener(MouseEvent.CLICK, GetfirstImage)
function GetFirstImage (evt:MouseEvent) {


gotoAndStop("P1")
}

2). thumb1_btn is a label for a converted button. P1 is an image on a keyframe that is labelled P1. There is also a standard stop command on a lower level which is designed to stop the flash file playing through all the images in a oner.

3). Rather than stop, I get all images flying past when I quickly render this out, and I get a returned error 1120: access of undefined property GetFirstImage.

I have been doing this tutorial. It worked fine until I started to mess around with it by adding text and motion tweens on another layer.... can't see where my error is.

开发者_StackOverflow中文版

I'm obviously missing something simple..... be gentle with me - it's my first time! Spike


When you add the listener you point to a handler called GetfirstImage (lower case f).

The handler function is named GetFirstImage (upper case F).

As a side note: it is the convention when coding in ActionScript to use a lower case letter as the first character of all function and variable names. Only class names should start with an upper case letter. This won't affect the execution of your code, but it makes it more readable for the rest of us.


As shanethehat said, you're pointing to GetfirstImage while your function is called GetFirstImage. Correct the function name like this:

thumb1_btn.addEventListener(MouseEvent.CLICK, GetFirstImage);

This will fix the error, and most likely will also rectify the flying images.

As a side note, don't forget to add semicolons on the end of lines when posting here (otherwise people might think you missed them out in your code).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜