Solved

Creating Multiple Buttons in Actionscript 3.0

Posted on 2008-06-09
9
1,821 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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 set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
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.

738 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