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.
Related
I have an animation that may stop at 2 points depending on what the user fills in, if the animation stops at one of the two frames an objects has to apear and have to disappear if the user continues with playing the animation again. Can someone tell me how I can let object appear if the animation stops at a certain frame?
Do I need something like this? I have very little experience so please help!
star_mc._alpha = 0; star_mc.onEnterFrame = function(){ if(this._alpha < 100){ this._alpha = this._alpha + 5; }}
The code looks ok.... try it... just put it in the right place!
It's hard to tell where because I don't know how your animation built!!
I am new to AS3 scripting. I have a wide image (movie clip "preform_mc") that I am masking and would like for right button ("right_mc") to dynamically move the image.
The code below moves the image to the right, but its not a dynamic movement (would like an animation effect) and I cant control when the image should stop moving, basically a max amount for the x coordinate.
any help is greatly appreciated!
right_mc.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
function fl_MouseClickHandler_2(event:MouseEvent):void
{
preform_mc.x += -100;
}
Take a look at Greensock Tweening Library. Using that library you'll be able to easily make a smooth animation of a moving image. For the control of max X you should write an if statement to check whether preform_mc.x is more than the max amount you want.
Code will look something like this:
var min_x:int = -500;
function fl_MouseClickHandler_2(event:MouseEvent):void
{
if(min_x < preform_mc.x)
TweenLite.to(preform_mc, 0.5, {x:preform_mc.x - 100}); // using the library I provided a link to
}
I have this interactive 5 seconds animated intro for a website. the preloader and one item are animating and i made the second animation follow the mouse cursor but it has to stay within a certain part of the stage to work with the other animation happening on screen.
I have this code on the movie clip
Mouse.hide();
potistiri.addEventListener(Event.ENTER_FRAME, newCursor);
function newCursor(event:Event): void { potistiri.x = mouseX;
potistiri.y = mouseY; }
and i like i said i just want it to stay in the area i want...
i found this code which gives me errors for not putting the staments if and else if correctly or that it needs a rightparen when i input my numbers in...
if(this._x>Stage.width){
this._x=Stage.width;
}else if(this._x<0){
this._x=0; }
but i cant get it to work...
i need it to move between x 208-656 and y 140-336 and when it gets out of that area the object stay there doing its loop and you see the normal mouse cursor moving in the rest of the screen.
thanks a lot in advance...im leaving my it to the experts in here to pls help me ouy!
The logic you're using in your if/else is fine for clamping the movie clip to a specific area, what exactly do your errors say?
In regards to seeing the normal mouse cursor again you could try using the same if/else checks to determine whether the mouse should or should not be hidden ie if the mouse is outside the area and is hidden, call Mouse.show(), else if it is inside the area and shown, call Mouse.hide().
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.
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.