Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating Multiple Buttons in Actionscript 3.0

Posted on 2008-06-09
9
Medium Priority
?
1,824 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

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!

Question has a verified solution.

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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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

604 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