Solved

Creating Multiple Buttons in Actionscript 3.0

Posted on 2008-06-09
9
1,817 Views
Last Modified: 2011-10-19
Hello,

I am very new to AS3, so forgive me for asking such a stupid question!

I have multiple buttons placed within a movieclip. I want each of these buttons to go to different frames on the main timeline.

If I assign the code "Button One" to home_btn, this actionscript works fine. However when I go to add the script for the other buttons it comes up with an error:

1120: Access of undefined property about_btn

What am I doing wrong here? Any help would be muchly appreciated!
import flash.events.MouseEvent;
 

//--- Button One ---\\
 

home_btn.addEventListener(MouseEvent.CLICK, hClick);
 

function hClick(eventMouseEvent):void{

	(this.parent as MovieClip).gotoAndPlay("home");

}
 

//--- Button Two ---\\
 

about_btn.addEventListener(MouseEvent.CLICK, aClick);
 

function aClick(eventMouseEvent):void{

	(this.parent as MovieClip).gotoAndPlay("about");

}

Open in new window

0
Comment
Question by:b_yellow
  • 5
  • 4
9 Comments
 
LVL 12

Expert Comment

by:SamuelRostol
Comment Utility
Hi there,

You're saying that the buttons go on different frames, and that might be the issue. If the button is not at the stage when you assign the code, it will not find the buttons movieclip, and therefore it will not add the eventListener to it. In other word - a error message will be thrown.

What you probably must do to fix this, is to move the code on 'about_btn' to the same frame where the button is actually on the stage. Either that, or have the button on stage but hidden from view on this frame, and then add a new keyframe where you want the button to be shown later on. Then it should work.

Good luck!
Kindly,
Samuel
0
 

Author Comment

by:b_yellow
Comment Utility
Thanks Samuel for your help!

However, the buttons are already all on the same frame with the code.

I just want the buttons to link to different labels (or frames) on the main timeline. I hope that makes better sense?

Thanks again,
Rach
0
 
LVL 12

Expert Comment

by:SamuelRostol
Comment Utility
Hmm, yes, I can see that I misunderstood you now :)

Could you upload the file? I'll take a look straight away.

It seems like you've misnamed the button or something, but this will be easier to see when I get the source.

Kindly,
Samuel
0
 

Author Comment

by:b_yellow
Comment Utility
Thanks Samuel,

I have uploaded the file. I think you might be right. I think I am naming my buttons wrong somehow...

I have uploaded the file here:

http://www.brightyellow.com.au/bymain.fla

Cheers,
Rach
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:b_yellow
Comment Utility
Samuel!!

I'm a total idiot! Sorry for wasting your time. I figured it out, I had the instance listed as a button, not a menu item.

Sorry that I'm a total loser!!

Thanks for all of your help anyways!

Rach
0
 
LVL 12

Accepted Solution

by:
SamuelRostol earned 50 total points
Comment Utility
Found the "bug".

You have each of the buttons on three keyframes (with a tween). The button must have the same instance name on each of these keyframes to actually register the name.

If you add the instancename to all three keyframes, your problem should be solved! I've attached the repaired file :) Just remove the .txt from the extension.

Kindly,
Samuel
bymain.zip
0
 
LVL 12

Expert Comment

by:SamuelRostol
Comment Utility
Hehe, well, my solution worked as well - so it proves that many situations has several ways to get out :)
0
 

Author Comment

by:b_yellow
Comment Utility
You're a star!
0
 
LVL 12

Expert Comment

by:SamuelRostol
Comment Utility
Hehe, no need to exaggerate - it was a pleasure to be able to help you somewhat, even though you found a solution entirely on your own :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now