MOUSE_OUT action not working? - actionscript-3

I am aiming for: when you put your mouse over the clip it plays and then stays on the last frame until the mouse is taken off, then the clip should return back to the first frame.
So far this code works that when you put your mouse over, the clip starts then stops on the last frame.
I also want it that even if you take the mouse off before the clip reaches the final frame it will still return to the first frame.
stop();
stage.addEventListener(MouseEvent.MOUSE_OVER, playMovie); function playMovie(event) { play(); }
stage.addEventListener(MouseEvent.MOUSE_OUT, stopMovie); function stopMovie(event) { stop(); }
stop();

Instead of using stop() in your stopMovie function, use gotoAndStop(1) to reset this to the first frame.
You may want to use the Event.MOUSE_LEAVE instead of mouse out if you're wanting this to happen when the mouse leaves the SWF entirely.

Related

How can I make these two things happen at same time when mouse roll over in flash

I have a movie clip called content. I want that when the mouse roll over the button, the content shows up and start playing the animation. Right now, When I mouse over, it play the movie clip, when I roll-out, it disappear which works fine. But the problem is the next time when I roll over again, nothing shows up. Any idea? Thank you in advance.
Here is my code:
code of the btn
btn.addEventListener(MouseEvent.ROLL_OVER, test);
function test(event:MouseEvent):void{
content.visible=true;
content.play();
}
btn.addEventListener(MouseEvent.ROLL_OUT, test2);
function test2(event:MouseEvent):void{
content.visible=false;
}
code for the movie clip:
Stop(); // 1st frame
Stop(); // last frame
You should replay your movie by using gotoAndPlay()
function test(event:MouseEvent):void{
content.visible=true;
content.gotoAndPlay(1);
}

MouseEvent in flash

I'm trying to make my own button in flash application. Here is some code:
addEventListener(MouseEvent.MOUSE_OUT, Out);
addEventListener(MouseEvent.MOUSE_OVER, Over);
...
private function Over(event:MouseEvent):void
{
addChild(overImage);
}
private function Out(event:MouseEvent):void
{
removeChild(overImage);
}
When mouse is over this button, overImage is blinking. Looks like Over and Out are calling each frame. What am I doing wrong?
If the mouse is positioned in a point where overImage will appear, then that child object will cause a MOUSE_OVER event on itself and thus a MOUSE_OUT event on its parent. The parent MOUSE_OUT will remove the overImage from the display list and that wil cause again a MOUSE_OVER over the parent, startin the loop once again and making the overImage to blink.
Since you tagged this with Flex; why not use a Flex Button?
The MouseOver event will fire continuously as the mouse moves. I would perform a check before calling the addChild to see if the overImage is already parented:
private function Over(event:MouseEvent):void
{
if(!overImage.parent){
addChild(overImage);
}
}
private function Out(event:MouseEvent):void
{
if(overImage.parent){
removeChild(overImage);
}
}
I suspect that will prevent the "Blinking".
Like the other guy said use ROLL_OVER and ROLL_OUT instead, OR set the button.mouseChildren = false.
The reason it's blinking is because MOUSE_OVER and MOUSE_OUT will for every child of that button. So if you have text, or a bg image / color, or a shine, or other elements inside of it, every time you roll over ANY of those parts, it's firing.
So when you add "overImage", it appears below the mouse, and that fires another mouseOut and mouseOver. Again, just use ROLL_OVER and ROLL_OUT, OR set mouseChildren = false
Just consider using MouseEvent.ROLL_OVER and MouseEvent.ROLL_OUT events. They ignore component's children. Without any additional checks and ugly tricks.
And by the way, buttons support skins and states, so you can just include your image into 'over' state.

dispatchEvent not working in piecemaker 2

i have tried to research this issue, but being a flash newbie i struggle to wade through the terminology...
i am using the piecemaker 2 slider on the landing page of my BudeStrings Dev Site. the slider contains a total of 5 slides; the first is a movie clip containing multiple frames and the following four are animated text clips consisting of only one frame each.
as per instructions i found on the interwebs, i added a keyframe after last frame of the first (multiframe) clip and added the following code:
dispatchEvent(new Event(Event.COMPLETE));
stop();
to stop the clip looping and to enable the autoplay behaviour of the slider. this works absolutely fine with the first (multiframe) movie clip, but when i try to add the same code to the other four (single frame) clips it does not have the desired effect.
these four clips use the following code:
var myString:String = "Sample text "
var myArray:Array = myString.split("");
addEventListener(Event.ENTER_FRAME, frameLooper);
function frameLooper(event:Event):void {
if (myArray.length > 0){
TextField.appendText(myArray.shift())­;
}
else {
removeEventListener(Event.ENTER_FRAME, frameLooper);
}
}
to display some text with an animated typing effect. if i add a keyframe with the dispatchEvent code as i did on the first clip it stops working and when i append the dispatchEvent code to the above actionscript it has no effect, and piecemaker 2 stops autoplaying when it hits slide number 2.
beyond that i have no idea what is causing the problem. please help.
regards, jan
First of all, you should use the appendText method on a textfield instance, not the class itself (the compiler should give you an error). So if the textfield on your stage is called 'txt' it would become 'txt.appendText..'. Secondly, you should define the event dispatching within the else section as at the time it runs, your animation would be completed.
[edit] make sure you enable strict mode in your publish settings

AS3 How would I make a figure do different animations based on keyboard input?

I am using Action script 3, and CS5.5. I wish to make my character animate different ways based on keyboard input. Like say if I press the right arrow key I want my run animation to start, and if I press the left arrow key I want to reverse that same animation. Then When there is no input I want him to be just standing, and when the up arrow key is pushed I want the jump animation to work. What is the best way to do this in action script 3?
Use frame labels to programmatically control the movement of the playhead on the timeline.
MEDIA
The character clip should have this structure:
-3 layers on the timeline, each with three keyframes for nine in all
--a frame label layer, giving a frame label to each frame ("standing", "walkingRight", "walkingLeft")
--a stops layer, which make each frame separate, so movement between the frames is only controlled by code
--a sub-animations layer, with one animation in each frame, all the animation looping and having no stops in them
---walk left animation clip
---walk right animation clip
---standing animation clip
Just to be clear, each of these nested animations takes up one frame, but if you move the playhead over it, it looks like that animation is playing alone, and it stays that way until your code moves the playhead.
CODE IT
var character:MovieClip=new MyCharacterClass()
addChild(character);
character.gotoAndStop("standing")
stage.addEventListener(KeyboardEvent.KEY_UP,keyUp);
protected function keyUp(event:KeyEvent):void
{
switch (event.keyCode)
{
case Keyboard.LEFT:
character.gotoAndStop("walkingLeft")
break;
case Keyboard.RIGHT:
character.gotoAndStop("walkingRight")
break;
default:
character.gotoAndStop("standing")
break;
}
}
This is the simplest possible example--click the left arrow, and the animation shows the character walking left (albeit in one spot, you need to add that actual movement code). Click the right arrow and it walks right. Press any other key and the character stands.
First off, you use KeyboardEvent to check for arrow keys being pressed. Then what exactly you do in the event listener function depends on how exactly your animations were created. For example, if what you're doing is playing MovieClips that were drawn in Flash, then switch the MovieClip in the KeyboardEvent listener.

AS3 for an animated button

I need help with AS3 for an animated button. The button (movie clip) I've created starts playing on a mouse-over but stops immediately when a mouse-out event occurs. But I want the button to finish the loop cycle before stopping the animation and play the animation on the next mouse-over from frame 1.
This is the code I have so far:
stop();
bt.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
function onMouseOver(event:MouseEvent):void {
gotoAndPlay(1);
}
Thanks in advance,
Jenya
It seems you're not playing the button but the button's container actually.
Maybe try :
bt.gotoAndPlay(1)
or
(event.target as MovieClip).gotoAndPlay(1).
All you should have to do is to add a to stop() on the first frame of the button so it doesn't loop forever.