Solved

Creating Multiple Buttons in Actionscript 3.0

Posted on 2008-06-09
9
1,818 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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. …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.

911 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

22 Experts available now in Live!

Get 1:1 Help Now