Accessing buttons from a movieclip to mainframe - actionscript-3

so I have a bunch of buttons inside a movieclip and I want to access the object of those and be able to modify them through the code of the mainframe, how can I do something like that?
I tried getChildByName() but nothing's happening.

Related

How to turn a shape into a button AS3

I have started making an advent calendar using the adobe flash professional software. I have drawn each 'door' individually with the draw tool on separate layers. I need to know how to use action script to wait for a click on one of the doors and then goto a specific layer and stop. I have tried different methods such as
button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
but it throws up errors.
Any ideas would be appreciated.
Thanks
If you drew the door it's still just a vector drawing that you can't really do anything with yet - you'll need to convert it to a MovieClip or a Sprite or a Button. The simple way to do this in the interface is:
Use the pointer to select everything you want to be contained in your MovieClip.
Press F8 OR choose "Modify" from the top menu and then "Convert to Symbol."
From there, you'll get a dialog box that looks like this:
You'll need to give it a name. This name will be the Class Name so call it something like "Door" or something descriptive like that. Leave the type as MovieClip and click "Ok."
Now you have the class so you'll have to give it an instance name. Select the object that you just created on the stage. In your properties it should look something like this:
Where it shows "instance name" delete that and give your object a name. In your code example you called it button so call it button here. Now you have an object that can listen for event listeners. Inside your handler you can write something like this.gotoAndStop(2) to get where you need to go.
Hope this helps!

MovieClip sticks to all frames

I have a MovieClip with 5 frames. On it are some other movieclips, quite a few of them. On every frame of the first MovieClip they are positoned differently and when I change the frame they change location. Everything works great until I change something within the actionscript.
If I try to color the child MovieClip or do anything with it and then change the frame, the MC stays on the same spot, it does not change location like it should (and does if I dont change it).
Why is this happening? Can I do something to fix it?
Thank you :)
Try changing the position of the movieclips dynamically, using actionscript on each frame, instead of directly on the stage.
[movieclip].x = [Number];
[movieclip].y = [Number];
I'm pretty sure objects that have been referenced in actionscript tend to ignore the IDE positioning in later frames, so you need to dynamically move them. I've seen it happen to me heaps of times.

Accessing List and TextInput inside a movieClip

I have a problem accessing a List and TextInput fields placed inside an MC.
What I'm trying to do is an animation for a menu. So I placed buttons and List and a TextInput inside a MC which I want to animate.
I'm trying to access them like this:
string_variable = mc_name.textInput_Name.text;
Everything worked fine before I placed those controls inside an MC. The code was, of course, without mc_name. prefix before that.
What am I doing wrong and how can I fix this? My goal is to make a complex keyframe animation of a clip with buttons and other controls inside it, specifically List and TextInput ones.
Thanks.
Most animations, especially UI, like menu blocks, lists, could be done with tweening engines. You will have more control over animated elements. MovieClip isn't a nice choice to use as mechanism to animate UI components that should be accessed.
Anyway, If you want MovieClips in your project, give same names to the components on the timeline on every keyframe. It will help, a bit...

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);

Merging MovieClips into a larger MovieClip

I have these 2 separate FLA (AS3) files and I want to merge them together. One FLA, let's name "Animation.fla", consists of a 1-frame animation with a class assigned to its main stage, let's label it "MainStage.cs." The other FLA file, label it, "Navigator.fla", consists of 3 frames where I have to navigate different frames to get to the animation on the Animation.fla.
I have tried nesting the two but I gain errors when trying to convert the whole Animation.fla to movieclip and put it on the frame of the Navigator.fla. It's seems it's not the correct way to do it.
Please fill me in with ideas on merging animations with Classes since I'm still new to this.
I have tried nesting the two but I
gain errors when trying to convert the
whole Animation.fla to movieclip and
put it on the frame of the
Navigator.fla. It's seems it's not the
correct way to do it.
This is one way to do it. It could be that your code has errors. Please post your code.
In the meantime, check if:
-your MovieClips have instance names
-you are referencing your MovieClips correctly in your code.
You could you create a new movieclip on the stage of Animation.fla and select all of the frames in Navigator.fla, right click and "copy frames". Then go back to Animation.fla and paste them into your new movieclip. This will work if you don't have a main class in Animation.fla.