?
Solved

Creating Multiple Buttons in Actionscript 3.0

Posted on 2008-06-09
9
Medium Priority
?
1,823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 12

Expert Comment

by:SamuelRostol
ID: 21748776
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
ID: 21748844
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
ID: 21748875
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:b_yellow
ID: 21748964
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
 

Author Comment

by:b_yellow
ID: 21748980
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 200 total points
ID: 21748994
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
ID: 21749014
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
ID: 21749015
You're a star!
0
 
LVL 12

Expert Comment

by:SamuelRostol
ID: 21749093
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

777 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