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.
Related
I'm a flash beginner, and I would like to create a button that will play a few frames following the frame it's on (a fade out), and then travel to a different part of the timeline. Is there an easy way to accomplish this? Or would it be easier to program a fade with actionscript instead of with an alpha effect?
Thanks in advance to anyone who can help.
It sounds like you have a frame with a few buttons on it and you want to have each button click through to playing a different frame but for all of those buttons to first perform some kind of fade out animation.
You can achieve this by storing a reference to the frame you want to go to after the fade out is complete. Something like:
var destinationFrame:int = 0;
And then when you click a button:
button1.addEventListener(MouseEvent.CLICK, clickButton);
function clickButton(event:MouseEvent):void {
destinationFrame = 40;
gotoAndPlay(<frame for fade out transition>);
}
Finally, at the end of the fade out transition:
gotoAndPlay(destinationFrame);
Simply allocate the relevant destinationFrame based on the button you click.
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);
}
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.
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.
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