How do I put a button on specific frame in flash cs4 - actionscript-3

i am using actionscript 3.0 , i want to create a button in a specific frame. I've created a button on frame 1 that goes to a specific frame, for example frame 2. this is the code i am using for the button.
button1.addEventListener (MouseEvent.CLICK, btn1);
function btn1(event:MouseEvent):void{
gotoAndStop(2);
}
then, on frame 2, i want to put another button that only visible or appear on frame 2 when you click the button on frame 1. Thanks

its a bit hack and bash but by default have the button on frame 2 set as invisible buttonName.visible = false..
Then add the following to your event handler
button1.addEventListener (MouseEvent.CLICK, btn1);
function btn1(event:MouseEvent):void{
**buttonName.visible = true;**
gotoAndStop(2);
}

Related

How do I change the size of a movieclip in flash by clicking on it? (Actionscript 3)

Everything I've found is for making a separate button, but I'm trying to make it so that clicking on the movieclip itself makes it change size. The reason is that it's being animated moving across the page, so clicking it is the challenge. Can anyone help? This is the code I tried:
info_btn_mc.buttonMode = true;
info_btn_mc.addEventListener(MouseEvent.CLICK, openInfo);
stop();
function openInfo(e:MouseEvent):void {
enemy_first.play("shrink");
}
You cannot use play("shrink"), the method
play() (Moves the playhead in the timeline of the movie clip) has no arguments. use gotoAndPlay/gotoAndStop instead that received an argument called frame:Object (frame number or label (String).
enemy_first.addEventListener(MouseEvent.CLICK, openInfo);
enemy_first.stop();
function openInfo(event:MouseEvent):void
{
trace('event.currentTarget:', event.currentTarget);
event.currentTarget.gotoAndPlay("shrink");
}

flash as3 first time a button pressed has no reaction

I am trying to make my first game in actionscript 3 and using 3 keyframes. this is the code from my first keyframe:
gamestart.addEventListener(MouseEvent.MOUSE_DOWN, start);
function start(e:MouseEvent):void
{
gotoAndStop(2);
}
And in my second keyframe, I have a keyboard listener.
stage.addEventListener(KeyboardEvent.KEY_DOWN ,pressButton);
function pressButton(e:KeyboardEvent):void
{
trace("aaa");
}
My problem is that, after entering the second frame, the second frame doesn't seem to get "focused on", which means I still need to click it to be able to use its keyboard events. Anyway to force focus on a frame?
Setting stage focus is as simple this:
stage.focus = stage;

How to load a movieclip and goto the first frame

I use a button in my header of my website to remove one movieclip (page of my website) off the stage and tweened another onto the page like so...
function moviesClick(event:MouseEvent):void
{
pageContainer_mc.removeChildAt(1);
pageContainer_mc.addChild(pMov);
TransitionManager.start(pageContainer_mc, {type:Photo, direction:Transition.IN, duration:1, easing:None.easeNone});
}
I have encountered a problem - if i have been on this timeline previously and gone from frame 1 to say frame 2 (another page in that area of my website) when i use the button in my head of my website again, i stay on frame 2 but i want to be returned to frame 1 always when this button is pressed (code above for my button).
How do i force this timeline to start at frame 1 whenever the button in my header (on a seperate timeline) is pressed?
Is the timeline in question the pagecontainer_mc? If so:
pageContainer_mc.gotoAndStop(1);
Edit based on comment discussion:
Assuming that's the correct path, this should work.
moviesPage.moviesHolder.moviesNow.gotoAndStop(1);

add even-listener to a button on timeline that is a grand child of a movie clip

I got a simple flash scene that contain movie clip that contain sliding button that changing every few seconds:
every layer contain a button and another movie clip.
If I want to add event-listener to a simple button on stage, i just write:
f4.addEventListener(MouseEvent.CLICK, f4Click);
function f4Click(event:MouseEvent):void
{
flash.external.ExternalInterface.call("dlHTCMD", "switchtogame?code=fnf50");
}
but when I'm trying to access the button inside the two movie clips, like
optContainer.optBeach.btnBeach.addEventListener(MouseEvent.CLICK, btnBeachClick);
and I'm adding a trace function to see if the event are triggered but nothing is happening.
looks like a simple problem but i didn't find a solution.
I thought about extending the button class and add a bind function with the value as the name of the button and set the Event Listener but I'm not an AS3 expert :(
Thanks.
Try this:
// Pass mouse events to children
optContainer.mouseChildren = true;
optContainer.optBeach.mouseChildren = true;
// Reset hit area
optContainer.hitArea = null;
optContainer.optBeach.hitArea = null;
// Reset masks
optContainer.mask= null;
optContainer.optBeach.mask= null;
Also check whether on each key frame button have name.

Applying action to a button in one frame makes it apply to whole movieclip in Flash CS6

I have a movieclip with several layers and frames. Some of those contain buttons. When I click button 1 I want it to go to the next frame. When I click button 2 I want it to go to frame 23. This is the code I'm using for button 1:
this.addEventListener(MouseEvent.CLICK, convnext);
function convnext(evt:MouseEvent):void
{
MovieClip(parent).gesprekkencivcen.nextFrame();
}
and this is the code for button 2:
this.addEventListener(MouseEvent.CLICK, convend1);
function convend1(evt:MouseEvent):void
{
MovieClip(parent).gesprekkencivcen.gotoAndStop(23);
}
What happens now is that when I click either of the buttons, or in fact anywhere inside the movieclip (even layers I haven't applied actions to) it executes both functions at the same time so I end up going to frame 24. Can somebody provide an answer to this problem?
Obviously this in both cases refers to the same object, and not to the buttons in particular. Record the names of those buttons as you've named their instances on the timeline, say button1 and button2 and write the code employing those names.
button1.addEventListener(MouseEvent.CLICK, convnext);
function convnext(evt:MouseEvent):void
{
parent.parent.gesprekkencivcen.nextFrame();
}
button2.addEventListener(MouseEvent.CLICK, convend1);
function convend1(evt:MouseEvent):void
{
parent.parent.gesprekkencivcen.gotoAndStop(23);
}
With this, however, you will need to update the link to gesprekkencivcen in both listeners, as those buttons will have this as parent, and their target apparently is not a child of this. I have tried to plainly set a call to parent.parent.gesprekkencivcen, which might not work.