Flash 8 :: GotoAndPlay - Loop Function Between Frames
Jun 13, 2011
I am working with some actionscript that are spread out amongst different frames, and having changing conditions, determines whether to end the sequence (gotoAndStop(1)) or continue (gotoAndPlay(5))
I understand this easy example could be done several ways on one frame easily, (while x<10, etc).. but my code is so long and complicated, that the way I wrote it, it was easier to have it sort of "loop" between frames. The problem with this is, I think the frame jumping is slowing the coding down. I tried functions, (like having all coding in frame 5 as a function, then calling that function with the "else" in frame 6), but that would only run the function once.. I need it to keep looping.
here is what I am trying to achieve in as3 in as2:
Code: var randomNumber = Math.floor(Math.random()*3) if (randomNumber == 0){ gotoAndPlay(1);
[Code]....
on frame 1, 30 and 60 there is a different animation, with this code at the end of each animation it randomly chooses one of the optional frames to play from.
I am looking for an actionscript that will go to a certain frame in the timeline, play several frames and then jump to another frame in the timeline. Basically, I want to use this on several different buttons that use the same animation sequence to get to another part of the timeline.
The following is a scenario, but not script: Buttons A and B are on Frame 1. Animation is on Frames 2-20: When Button A is pressed, go to Frame 2. Play Frames 2-20, then go to Frame 21. When Button B is pressed, go to Frame 2. Play Frames 2-20, then go to Frame 22. I am currently doing this in a different way.
Buttons A and B are on Frame 1. Animations for Buttons A and B are the same, but are located on different frames. Animations for Button A would be on Frames 2-20. Animations for Button B would be on Frames 21-39. So... When Button A is pressed, go to Frame 2. Play Frames 2-20 and stop on Frame 20. When Button B is pressed, go to Frame 21. Play frames 21-39 and stop on Frame 39.
Do I have to create this extra timeline? Can I just put the animation in a separate movie? How can I play the movie and then connect each button to different parts of the timeline after the movie ends?
created a (what I thought was simple) gallery.I have all the large images on a timeline layer were each image fades in over the course of half a second then stops. I created navigation buttons, next and previous on each frame that are supposed to navigate to the next image. The action script for the nav buttons is different depending on which image (frames) you are on. However, when I publish the swf the next and previous buttons don't go to the frames I prescribe for them in Actionscript, but just go to random frames in the timeline. Also, I have a series of thumbnails that have actionscript that navigates to pictures/frames when clicked so I don't know if they are interacting badly. Does anyone have any idea whats going on?Here's an example of the AS for the previous and next buttons (instance names prev_btn and next_btn):
prev_btn.addEventListener(MouseEvent.CLICK, navback1); function navback1 (event) {
It seems like no matter where I check, there isn't a clear answer to this particular issue.Rather than blabber on about the code, I think it is important for me to address that I may just not be setting up my document correctly. At present, I created several layers, some in folders, for a basic portfolio website. I have my problems with my main buttons, in my "Sections" folder, where each button is a distinctive layer so it can be animated when it is pressed.I have a button called 'architecture' that is pressed, but instead of just statically moving the frame to the desired content, I want to play 5-7 frames that I tweened for a small transition (sometimes opacity, sometimes sliding mask) that occurs right before the content. All my transitions and everything is just on this one main timeline.
Basically, I sort of want to have the best of both worlds, where I can goToAndPlay, but then stop it at the end of that segment, as to not run into my next frames of content.My first solution was to simply place a stop(); at the end of the transition, but then the menu just locks and stops. Of course this was on my top layer named 'actions.'I then tried applying each event listener to it's buttons' layers, but that resulted in the button simply not working.I segmented up the actions layer into keyframes, but then realized that it didn't call on the event listeners if I did that.
We have 5 buttons that each go to another frame e.g Product, Contact etc. but we want to play the same series of frames (an outro) and then goto the frame that corresponds to the button. Weve tried lots of different examples from the already posted questions and nothing will work. The latest I tried:
I have an main.swf that loads home.swf on the stage. In home there are mc's that when clicked take you to different frames inside home.swf I need to have a gotoAndPlay eventlistener off a button which would take the user back to frame one of home.the home .swf has 6 frames with different clips in each frame on one layer, text for the back to first frame on another layer, an invisible btn and an actions on two separate layers
first question :
the individual frames are 7-8-9 the gotoAndPlay action is on frame 7 ONLY the button only works when in frame 7 if 8-9 are not individual blanks why doesn't the button work when in frames 8 and 9?In other words can't I use an action that triggers a function assigned to a button that spans across more than one frame?if the button spans across 7 - 8 - 9 and the action frame is on 7 how can I get this to work?
I am using the below function in one of my application, but its not working. It says 1120: Access of undefined property btnTwo.
For button I have given the instance name as btnTwo btnTwo.addEventListener(MouseEvent.CLICK, btn2); function btn2(event:MouseEvent):void { gotoAndPlay(24); }
Basically I have a MC called 'plane3.' Inside that MC is another MC called 'plane2.' Inside 'plane2' is an animation on frame 5.(inside the MC 'plane3' the MC 'plane2' is on a classic tween going side-to-side from frame 1 to 99, once it gets to frame 99 the code gotoAndPlay(1); makes it go on loop back to the beginning)My question is how would I go about: when you click 'plane3' it lets the tween continue playing until frame 10, then on frame 10, it gotoAndPlay (100); in the same MC and ALSO plays frame 5 from inside 'plane2'
to call a function that uses gotoAndPlay to send the playback head to a certain animation on the timeline.
function doStuff(evt:Event):void { gotoAndPlay("popped"); }
Should be so simple. But the first frame of the "popped' animation, often the first 2, do not display. (when testing the compiled app, even the first 3-4 frames often do not display)Without the mouse event listener, using gotoAndPlay("popped"); to move the playback head to this animation from another spot in the timeline works just fine, so that's why I suspect the mouse event is involved in the bug.using
trace(currentFrame);
in the function after gotoAndPlay, does trace the correct first frame number of the animation, but this frame is not displayed, the animation just starts with the 2nd frame, or 3rd..or sometimes 4th.
how to literally describe what I want to achieve. But I believe it is an easy achievement for someone who is a little familiar with Actionscript (2).
I have a movieclip with backgrounds that fades in and out as the timeline within the movieclip plays. What I wanna do I place an actionscript at frame 1, before any of the background plays, that randomizes a gotoAndPlay function that jumps to a decided frames out of frame 2, 77, 152, 227, 302, 377 etc.
It should be a problem to use the same actionscript after each background has been shown? If it is, its no problem, doesnt matter too much. As long as the first background that is getting randomized is different each time you visit the website.
gotoAndPlay function not working, I am getting this runtime error "Error #1009: Cannot access a property or method of a null object reference."I understand its meaning, what is the reference that is null here , even keyframe 3 exists.
How can I get a movie clip to play when pressing the right arrow key? The movie clip is called helicopter and it has stop(); on its first frame (with an animation following).
Here is the loop that tells the arrow keys what to do when pressed:
public function loop(e:Event) : void { vy += gravity; y += vy;
If you place a for loop in a recursive function with the function call within the loop... will the loop finnish or does it stop working untill the last recursion?
is there anyway to have a button play frames 5-10 on a movie clip inside the current frame, as well as skipping to...lets say...frame 10 of the scene?
i want to create a site where buttons go to different pages, but those pages have animations in and out.so if someone is in one page, and clicks a button to go to another, that page plays the "out" animation while the other page plays the "in" animation.
On my first frame, I have: 6 buttons (p1 through p6). A holder mc_holder, which holds mc_pages, {a movie clip that shows 6 pages (each their own movie clip, page1 though page6) tweened across the screen, made to look as if the pages are being "flipped" through).
The following code: Code:stop(); var _holder = mc_holder.mc_pages; var picked;p1.goal = 1; p1.onRelease = goPage; p2.goal = 10; [Code] .....
The problem is, as soon as the movie loads, ALL these animations begin to play. I am looking for a solution so that the animations will not play until the page is viewed. I am thinking I can put a stop on the first frame of each page, and a frame label ("go") on the second frame. Can I add this (my knowledge is limited but say... gotoAndPlay (go")) to the code shown above? I have tried messing around with it but have not yet had any results.
Im making an "intro" for a website.. first some picture come in and when you click one of them all picture goes to bottom of the flash.. My problem is: I need it to Frist. gotoAndPlay "the frames" THEN link.. the "movie" takes about 3 secounds.. Is there some sort of code i can use to "tell it to wait" and then link? this is what i got so far. (i know its wrong hehe)
I'm constructing an area with selectable buttons that transition and appear every 10 frames. During these 10 frame transition periods I don't want the buttons to be selectable and if possible to disable the rollover.
I've tried creating an If statement on the addEventListener so that it only works when currentFrame is 11,21,31 etc but this didn't work. I then also tried the same principal on the function to which the Event Listener relates but still no success.
I am making a character walk. This code will make him wobble to the right and when thats done it will trigger him to wobble to the left and then call the function again to continue the loop.I can get the loop to work fine by calling the function but how do I STOP the function? Also I want to call it later on. Is there a way to start and stop a function?
So I'm trying to make an walking animation but I don't want to move a symbol in motion tween for each part of the leg each time. So how can I make a loop of it?
I want to be able to loop using gotoAndPlay 3 times through a certain section of frames in my flash movie after 3 times is up I want to be able to continue on to the next frames untill the end of the movie.
I'm trying to loop an embedded mp3 but only on certain frames, labeled (TOC1, TOC2, and TOC3). I labeled fourth frame "test", but when it gets to this frame it continues to play.
I would like some help on writing a piece of code.I need to write a function that if some movie clips are in some x and y value, then gotoAndPlay('end');
Code:
function gotoEnd() { if (tv_mc._x = 41.8; tv_mc._y = 157.3;) then gotoAndPlay('end'); }
I'm a bit rusty in flash. import mx.transitions.Tween; import mx.transitions.easing.*; var mytween:Tween = new Tween(ball_mc,"_x",Strong.easeInOut,-320.10,47.90,5,true); mytween.onMotionFinished = function() { var mytween2:Tween = new Tween(ball_mc,"_x",Strong.easeInOut,47.90,-320.10,5,true); } mytween2.onMotionFinished = function() { gotoAndPlay(2); } It does the first and second tween but doesn't do the gotoAndPlay function?