I tried to search it on google but no one was matched to my search.
Anyway, I'd like to create a custom play / pause button for the animation to control the animation and the audio. I am not so familiar with ActionScript 3 so beg for me.
Here's my screenshot so you can see what i mean.
Thanks and looking forward.
You need to create a layer with one keyframe at the begin, and normal frame till the end of your animation.
In this keyframe, you'll put the button for play/pause control.
On the document class (or sigh on the keyframe itself) you'll put something like that.
myPlayPauseButton.addEventListener(MouseEvent.Click, playPauseHandler);
function playPauseHandler(e:Event):void{
if(e.target.currentFrame == 1) // button is in the play state
this.stop();
else
this.play();
}
please note that the "this" reference in the handler function, is referring to the main scene (the _root for the as2 programmers).
Note also that you can access this.currentFrame in order to know the current frame of the main animation.
myPlayPauseButton.addEventListener(MouseEvent.Click, playPauseHandler);
the Correct
myPlayPauseButton.addEventListener(MouseEvent.CLICK, playPauseHandler);
Related
I'm working in Flash CC and trying to get the scrollwheel to control which direction and at what speed the animation is played. Here is what I have so far:
function handleMouseWheel(event:MouseEvent):void {
trace("The delta value is: " + event.delta);
var frame:int = (currentFrame + event.delta);
gotoAndStop(frame);
}
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
I haven't used Flash very much and I was told that I need to assign the name "clip_mc" to the object on the stage via the Properties panel, and I'm not exactly sure what that means. (especially since this piece of code affects the entire file and not just a single object)
Although, I'm not getting any errors, my animation is just playing normally and is not affected by the scroll wheel.
Thanks for you help!
it would be better to create a movieclip with your animation inside it
then drag that moviclip to the stage
give it a instance name like myAnim (in the top right corner of flash properties panel while the movieclip is selected)
then in the code type myAnim.stop();
to make sure when you start the swf animation will be paused, which is why your anim keeps just playing as default
then add your event listener
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
then in the handleMouseWheel you can then reference the movieclip and control it like
myAnim.gotoAndStop(frame);
hope this helps
Remove the add event listener from inside handlemousewheel() and where you say currentFrame you are referencing the current frame of the main timeline not myAnim. To do that you would have to say myAnim.currentframe = event.delta.
You need to make sure the event.delta corresponds to the frames you have and you may want to encapsulate it within a math.clamp to make sure it doesn't go too far.
I am building an SWF panel with support for English and Japanese, and a button to toggle between them. The English is on frame 1, the Japanese on frame 2. On the first frame there is this relevant AS3:
btnLangToggle.addEventListener(MouseEvent.CLICK, onLangToggle);
...
this.stop();
...
function onLangToggle(e:MouseEvent):void {
if (MovieClip(root).currentFrame == 1) {
MovieClip(root).gotoAndStop(2);
} else {
MovieClip(root).gotoAndStop(1);
}
trace(MovieClip(root).currentFrameLabel);
}
I click the button and the event handler function runs fine, once. If I click it again, nothing happens. Why?
Edit: Here is what my two frames and timeline look like.
If I click it again, nothing happens. Why?
Because It's a MovieClip and they are designed for animation, not for application states. Objects on the scene in first frame isn't accessible in the second key frame.
I assume in your case you have button for toggling language with different instances of MovieClip(Different languages). In second frame apply again event listener for the Japanese version of the language button:
btnLangToggle.addEventListener(MouseEvent.CLICK, onLangToggle);
Also, please read about Document Class, It's pretty simple create application with only 2 states, like you have (with 2 frames...)
I assume you are using key frames for the button, right?
You must be sure that the button is the same on both frames. Which means you must not use key frames - instead use separate layer for the button with a single keyframe and two normal frames. This way your code will work as it's the same button.
I'm Super New to Programming in general and very New to Actionscript 3. It's been a rough but fun ride.
Anyway For the work I am doing I have my animation Play up to a certain point and it asks the viewer a question, The viewer has 3 choices, and each of those choices are connected to a button on the keyboard. A B C or D.
After searching for someone with a similar problem, My solution so far is this:
stage.addEventListener(KeyboardEvent.KEY_DOWN, cNote);
function cNote(event:KeyboardEvent):void {
trace(event.keyCode);
if (event.keyCode==67) {
gotoAndPlay(21);
}
I have this repeated 4 times each for the different Keys.
This works and allows me to move the viewer to the Frame with their response, however Any time during the animation they can press the button and it will move them to the Frame of the corresponding button (in this case Frame 21). How do I set it so that the keypress will only respond and move them to Frame 21 when they are on Frame 20 for example? (I suspect it has something to do with the "stage" part in the code but I cant get it to work without it.)
I also have the audio for the animation on a separate Layer and even though the visuals change as it goes to the correct frame, the audio continues as if the key was not pressed. Is there also a way to connect the key to make it stop the current audio and then play the new audio? Or is there a better way to do this?
Sorry if this is confusing. Thank you for your help :)
It has been quite awhile since I touch flash. From what I remembered, you can click on the frame at your movieclip, insert a keyframe by pressing f6, and press f9 to insert the listener at that frame and that frame only, after an input has been pressed, you remove it. for example:
if (event.keyCode==67) {
gotoAndPlay(21);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, cNote);
}
For the audios, I usually plays them using code, but I'm quite sure there's a way to drag and drop the audio from library to the movieclip. so I can do sound1.play(), when a button is pressed, I can do sound1.close() and sound2.play()
For more reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html
I know this question has been asked before but as a noob i did not understand the answer so im hoping someone can explain a little more for me.
I have an arrow animated along a path using a motion tween I want when a button is clicked for an endless stream of arrows to follow the path, this would be easy if you could put more than one object on a motion tween but you cant? Can anyone help with the code id need to make this happen.
Is there a way to repeat the movieclip again before its finished to give this effect?
Do you have any code, or example of exactly what you're trying to accomplish?
You can use multiple instances of the same movie clip... So (for the sake of explanation) you could animate your arrow once, make sure it's its own movieClip, put it on the stage, and test your movie...It will loop over and over. You can drag as many instances of this movie on to the stage and they will all play, over and over until it's told to stop.
If you need ALL of the arrows to be one movie clip, as to be one addressable object, you can simply select all of your positioned arrows, and convert those into one movieClip (right click, convert to Symbol)
Of course all of this can be controlled precisely through code, but need to know a bit more about what you're trying to do. hope this helps a little...
The function play() will loop your movie forever, unless you have a stop() function somewhere.
yourMovie.play();
If you want to "repeat" / "reset" a MovieClip at any time, use gotoAndPlay() :
yourMovie.gotoAndPlay(1);
If you want to verify if you are at the end of your clip, use the properties currentFrame and totalFrames :
if (yourMovie.currentFrame == yourMovie.totalFrames)
{
// ex. if you want to stop
yourMovie.stop();
}
Ref : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html
Hope that help. Be more specific, if it doesn't answer your question.
I am a beginner with AS3 and I'm having a problem with MovieClip class.
I have a character that move through a simple script that handles collision, sound etc. Everything was working seemlessly so far but when I started adding animation, the character would stop at the end of the animation cycle.
Does someone comfortable with AS3 knows what's wrong here ?
Thanks in advance =)
Inside the Flash IDE, try clicking the instance of your character that's not looping the way you want it to (and this should be from outside the animation itself; from the container of your character), then look inside the Properties tab/window. Near the bottom, there will be a LOOPING header, and inside there you can modify the behaviour.
In case you have any problems with this, or otherwise want to have more control over the animation playhead, you can include script in the form of e.g. gotoAndPlay(1); which you might add at the last frame of your animation cycle to tell Flash to play from the start again. The frame number parameter doesn't have to be 1 of course. You could for example set up a series of animation sequences on a single timeline, and use gotoAndPlay() to have them loop internally, until an event occurs and you direct the playhead to another animation loop inside the same MovieClip.
Usually when play(); is called, an animation is being repeated all the time.
You should seek in your code for stop(); that essentially makes an animation stop, and remove it.