0

I have created my own buttons and imported them to the stage. I then tried to code them so that they linked to another page, however i get the same code message '1120 access of undefined property' for each of the coded buttons.
The code is as follows:

stop();
Index_btn.addEventListener(MouseEvent.CLICK, Click);
T_btn.addEventListener(MouseEvent.CLICK, Click1);
C_btn.addEventListener(MouseEvent.CLICK, Click2);
B_btn.addEventListener(MouseEvent.CLICK, Click3);
H_btn.addEventListener(MouseEvent.CLICK, Click4);
I_btn.addEventListener(MouseEvent.CLICK, Click5);

function Click( event:MouseEvent):void {
	gotoAndStop("31");
}
function Click1( event:MouseEvent):void {
	gotoAndStop("32");
}
function Click2( event:MouseEvent):void {
	gotoAndStop("33");
}
function Click3( event:MouseEvent):void {
	gotoAndStop("34");
}
function Click4( event:MouseEvent):void {
	gotoAndStop("35");
}
function Click5( event:MouseEvent):void {
	gotoAndStop("36");
}
2
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by snitch321
0

Believe it or not, I think it's your gotoAndStop() calls in your click handlers that are causing the error.

If memory serves correctly, when you use addEventListener to attach an event handler function to an instance of an object of any class, I think the code in the handler function refers to the attached object. So the handler has the objects scope rather than global scope.

In other words, your gotoAndStop() calls are trying to make your buttons gotoAndStop at the specified frame rather than making the parent movieclip stop at the specified frame in the timeline.

Now, you've said that you're using your own custom button class. I know if it was me, I'd derive from Sprite, so I'm assuming you've done the same....
If this is the case, then you should be informed that gotoAndStop is not a property of the Sprite class. Which is most likely why you're getting the error you mentioned! A Sprite is basically a MovieClip without a timeline, so there is no need for things like stop(), play(), gotoAndStop() or gotoAndPlay().

If your buttons are derived from MovieClip, it could be because your button clip doesn't have thirty-something frames!

So how do you get around it and access the timeline of the parent clip?
Well, I know that in traditional timeline based flash programming (in AS1/AS2) you'd use _parent to refer to the parent clip.
So to access the main timeline from your button instance you'd need to use:

_parent.gotoAndStop(insert_frame_number_or_label_here);

But I'm not sure if this way of doing things still applies in AS3...I haven't done any timeline stuff in AS3 yet 'cause I don't own a copy of CS3 or CS4.. But as the timeline is still available in CS3/CS4, I would assume that the _parent and _root commands are still in there and that things can still be done this way!

Personally I've been using FlashDevelop for all of my AS3 projects, so I create classes for everything and leave all of that nasty layer and timeline based nonsense behind!

I think for now, perhaps try:

_parent.gotoAndStop(insert_frame_number_or_label_here);

In your handlers and see how you get on!

Like I said, I'm not 100% certain, but I think that's most likely the problem!

Cheers for now,
Jas.

0

well thanks for trying but it didn't work. And whats interesting is that the '1120' error only refers to all the 'AddEventListeners' code lines, but not the event function handlers?
i would be prepared to give any1 the file to look at cause this is confusing me this error.

0

That's really odd!

What class/classes are your buttons derived from?

It sounds as if addEventListener is not a valid property of your button class...I'm not sure what's going on there!

0

I had a extra look around forumns about the 1120 problem and realized that i did not fill out the instance name property of the buttons. Even though i thought i already named them when i created them? and had the buttons named in the libary.

but anyway thank you once again for your attempts to solve my problem.

0

Ah of course, the instance names..The other factor in the timeline based flash development...Now you say that I remember a member of the dev team at my last job having errors pertaining to accessing undefined properties and the problem turned out to be a movieclip without an instance name. but that was AS2 and many years ago!
Heh heh!

Still, I'm glad you managed to get it sorted!

I've really got to try to scrape some cash together to get CS4 at some point. Flashdevelop is great and all, but sometimes some quick and dirty timeline stuff can be much easier than trying to code everything manually. I do miss it sometimes! It's been ages since I did any timeline based stuff, and as mentioned I haven't been able to try it with AS3....yet!

Oh yeah, and regarding my original post...I did a bit of digging and found that I was barking up completely the wrong tree with the function scope thing.

If you added you click handler code to your button by opening your button clip and adding code to its timeline, then your function would be scoped to the button object and would require the _parent. notation to access the main timeline (in traditional timeline based AS1/AS2 at least!). Whereas attaching the function to your button as you've done, from the main timeline allows you to directly use gotoAndStop to control the main timeline..So sorry about that.
I must be going senile! heh heh!

0

ahh yes i fully understand your explaination. haha i see what your saying, that the declaration of scope really only affects as2-since thats the last action script you can define actions in the button object and not the frame actions.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.