Targeting Root from a Movieclip - actionscript-3

Im having trouble targeting back to the main timeline from within a movie clip AS3.
I have tried the code below but still does nothing? I have labelled the frame in which I would like it to go to on the main time and added this code to the actions within in the movie clip, but when I click the button it does nothing? I have no errors come up?
Any ideas?
map_UK.addEventListener(MouseEvent.CLICK, MAIN);
function MAIN(e:MouseEvent):void
{
MovieClip(root).gotoAndPlay("MAIN");
}

Related

Actionscript 2.0 flash

I have written this basic button code a thousand times before on CS5. Now I bought CS6 and this simple AS2 code is not working.
On the first frame I made a movieClip symbol and added in its actions :
on(release){
gotoAndPlay(2);
}
Then I made a new layer on top, I typed :
stop();
in the frame's action.
Problem: From the second frame the animation was supposed to start, but it didn't work and stayed on the first frame even when I clicked the button several times. How to fix this issue?
I have even tried :
rooting on(release)
{ _.root.gotoAndPlay(2); }

how do I link a button inside a movie clip into the mainframe (flash CS6 AS3)

i have made a movie clip with some buttons inside. The idea behind this was to allow a scrolling system to be used. The only problem is i can't seem to figure out how to link a button inside a movie clip with a frame from outside of the movie clip and on the main stage.
My code atm is:
stop();
import flash.events.MouseEvent;
sports1.addEventListener(MouseEvent.CLICK,sport1)
function sport1(e:MouseEvent)
{
MovieClip(root).gotoAndStop(sports)
}
What i would like to happen is that each button inside the movie clip will take me to a certain frame on the main stage, like a navigation system. I am really new to flash so i may not understand all the technical terms yet, so be easy on me :)
So if you are creating a Main Movie Clip on the Stage and have inner Movie Clips that are acting as buttons. You want those inner buttons to take you to different frames on the main stage when the user interacts with them.
This is how you would do so.
What you would need to do as you already done give the Main Movie clip holding the inner buttons an instance name sports1 any inner button would also need an instance name say a button has an instance name of mcButton to access that button you would need to call on it like so:
sports1.mcButton.addEventListener(MouseEvent.CLICK,sport1)
sports1.mcButton.buttonMode = true;
then if you want that button when clicked to go to frame 2 on the main stage you would simply do this in the sport1function:
function sport1(e:MouseEvent):void
{
gotoAndStop(2);
}
I threw in the sports1.mcButton.buttonMode = true; that way it shows that it is interactive ie click able

How can I make a button inside a Movieclip send me to a frame in the main timeline?

I made a movie clip with an animation of a pull-down menu in which 3 buttons appear. The thing is, I'd like for those buttons to send me to an exact frame within the main timeline, and I haven't quite understood how it can be made.
The movieclip is located within a frame inside the main timeline, and its structure is kind of like this one.
The frame "Sucesos" is not within the timeline of the MovieClip, but in the Main Timeline, whereas the Button "IrSucesos1" is located inside a frame within the movie clip. The code I use is this one.
function LinkSucesos1 (event:MouseEvent):void
{ gotoAndStop("Sucesos1");
}
IrSucesos1.addEventListener(MouseEvent.CLICK, LinkSucesos1);
I don't know whether I should put the code inside the timeline of the movieclip or on the main timeline in the frame the movie clip is located, or if the code is the right one.
How do I make the buttons work by sending me to the frame that I want to get to in the main timeline and then have it stop there? What is the code, and where should I put it?
If I've understood your structure the way I think I have, the following should work. On your main timeline, add a new layer called Actions and on the frame that has the movieclip containing your buttons add a keyframe to this layer. Go to the movieclip that contains the buttons. Open the actions panel and type Stop(). Create a new layer called Button actions, click on the (blank) kayframe on this layer and add the following code:
import flash.events.MouseEvent;
my_button.addEventListener(MouseEvent.CLICK,on_click)
function on_click(e:MouseEvent)
{
MovieClip(root).gotoAndStop(5)
}
You'll need to change my_button to the button instance you'd like to assign the event listener to and 5 to the frame you want to go to on the main timeline. Test your movie - hopefully this should work for one button. For the others to work, simply give them each their own event listener and function to do what you want them to (ask if you get lost!).
stage is available anywhere where the displayObject is linked to the stage.
You can give a reference object to that control button. Your timeline object won't change so its fine.

Why isn't this click event being fired?

Why isn't the myMouseClick event being fired?
myMC:TestMC = new TestMC();
myMC.addEventListener(MouseEvent.CLICK, myMouseClick);
addChild(myMC);
function myMouseClick(e:MouseEvent):void {
trace("clicked");
}
As far as I can tell from the tutorials I've seen, that should work. For a moment, I thought that since I was adding the event listener to myMC, I needed to have the event function inside the myMC class, but that didn't work. Just gave an error about accessing an undefined property.
If it helps any, TestMC is a seperate .as file that extends movie clip.
I'm just trying to make it so when the movie clip itself is clicked, it does something. The movie clip itself will be following the mouse.
The object I was trying to click was made up on vertical lines. Apparently the whole movie clip isn't a collider... just the pixels in it, so when I was clicking, I wouldn't hitting enough of it. Changing it to a box worked. I could probably nest it if I wanted the same design, but that's fine.

AS3 Issues: Using a button to call a specific label frame on another movieclip

I am trying to figure out how to make it so I can click a button on the main timeline and have it jump to a frame inside a separate movieclip on the main timeline. This is the goofy code I have at the moment, but this is after a lot of changes, so who knows where I am right now. This is for a simple virtual pet game and I'm not sure why I'm having such a hard time with this particular issue. I'm missing something big.
function Shower(event:MouseEvent):void {
MovieClip(this.Egg).gotoAndPlay("shower");
}
// buttons
clean_btn.addEventListener(MouseEvent.CLICK, Shower);
It seems like you're writing this on the Timeline, and not in a class. You don't need MovieClip(this.Egg) to access the movieclip you're trying to play. Instead, it should have an Instance Name (for example, "my_mc"), and you can just call it like this:
function Shower(event:MouseEvent):void {
my_mc.gotoAndPlay("shower");
}
// buttons
clean_btn.addEventListener(MouseEvent.CLICK, Shower);