Adobe Flash. Mouseover animation endless loop - actionscript-3

I'm having some problems while making a button for a site. I created a button and an animation, then imported that animation as an .swf to the button file. I used the following code(with btn being the button and mc the movie clip):
btn.addEventListener(MouseEvent.MOUSE_OVER,btnF);
function btnF(e:MouseEvent):void
{
mc.play();
}
As you can imagine, when the mouse is over the button, the animation plays, but it doesn't stop... Any Solutions?
Details: Using Actionscript 3.0
And yes, i made the movie clip with a stop() code at the end... so I don't see why it loops.

It might be simpler to do it this way: create a button, on default state have the graphic for the button. On the over state use a movieclip with your animation. That should work without any code

The problem is that the MOUSE_OVER event will always fire if the mouse is over that "btn" display object. So the stop() code works at the end, but the play overwrites that command.
Here is a possible solution:
btn.addEventListener(MouseEvent.MOUSE_OVER, btnF);
function btnF(e:MouseEvent):void{
{
if(mc.currentFrame == 1)
{
mc.play();
}
}

//i called the instance of the button : buthead and the instance of the movie clip : head_mc
//on the first frame of the movie clip, i've put a stop function
buthead.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void {
head_mc.play();
});

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;

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.

How to play movie clip just once?

I've done some research on this site and figured out most of what I want to do. I click on a block. The block moves. When done it plays another movie clip. Problem is it loops the second movie clip. I found one query that deals with this but can't figure out how to make it work with the below code. Once the if statement is true it just keeps playing the clip (as it should), but I dunno how to make it play just once. Any suggestions much appreciated.
block_1.stop();
block_1.addEventListener(MouseEvent.CLICK, block_1_Click);
function block_1_Click(e:MouseEvent):void {
block_1.play();
}
block_1.addEventListener(Event.ENTER_FRAME, wavePlay);
function wavePlay(e:Event):void {
if (block_1.currentFrame==block_1.totalFrames) {
wave_mc.play();
}
}
Adobe's doc about the ENTER_FRAME event says:
[...] Dispatched when the playhead is entering a new frame. If the playhead is not moving, or if there is only one frame, this event is dispatched continuously in conjunction with the frame rate. [...]
That means that the ENTER_FRAME event keeps running until you remove its listener.
Your code should be:
block_1.stop();
block_1.addEventListener(MouseEvent.CLICK, block_1_Click);
function block_1_Click(e:MouseEvent):void {
block_1.play();
}
block_1.addEventListener(Event.ENTER_FRAME, wavePlay);
function wavePlay(e:Event):void {
if (block_1.currentFrame==block_1.totalFrames) {
wave_mc.play();
block_1.removeEventListener( Event.ENTER_FRAME, wavePlay );
}
}

currentFrame identifiers [AS3]

I'm completely new to Flash and AS3, and I'd have thought this would be a simple question, but I've been unable to find an answer online or in the documentation. I'm trying to use addEventListener (Event.ENTER_FRAME) and (.currentFrame) to disable a button for part of an animation sequence. While the animation sequence fades in, the Button Hand cursor is visible and people can select it before the sequence is completed. I want this button disabled for the first 213frames of the main timeline, which is when the button becomes visible.
Earlier, I was successfully able to disable a Rewind button for parts of a different movie scene using the code below with a few insignificant things changed.
Skip_btn.addEventListener(MouseEvent.CLICK, SkipToGoToScene);
function SkipToGoToScene(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1, "Opening");
}
//Skip_btn functions
Skip_btn.addEventListener(Event.ENTER_FRAME, skipDisable);
function skipDisable(event:Event) {
if (this.currentFrame < 213)
{ Skip_btn.mouseEnabled = false;
} else {
Skip_btn.mouseEnabled = true;
}
if (this.currentFrame > 213) {
Skip_btn.removeEventListener(Event.ENTER_FRAME, skipDisable);
}
}
The problem is that before I could just use "this.currentFrame" as the button was on the same timeline that it controlled, whereas now it's embedded in a MovieClip that is on the main timeline. What can I swap "this" for so I can reference this main timeline? Also, could someone fill me in on what the other "identifiers" are for ".currentFrame", as I'm not too sure how it works. The documentation examples ask for Movieclips such as "MyMovie_mc.currentFrame", but what if you just want to reference a main timeline?
If the button is on main timeline you could just use
this.root.getChildByName("Skip_btn").mouseEnabled = true;
And if you start playing animation on main timeline use
MovieClip(this.root).currentFrame