Looping frames with currentFrame & totalFrames AS3 Snippet

Looping frames with currentFrame & totalFrames AS3 Snippet
16th January 2012 Shane

In this tutorial we modify our swipe code so that, a left swipe on our last frame will loop to the first frame and a right swipe on our first frame will loop to the last frame.

I’m using the hideLogo_completeC.fla file from the previous tutorial sample files and have added a conditional statement inside our swipe code, in which we use the “currentFrame” and “totalFrames” properties to loop through the frames.

Note: Directions are reversed on a mobile device, so a swipe left would go to the next page and a swipe right would go to the previous page.

I have added the following conditional statement to our swipe right code.

if(currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
{
prevFrame();
}

Above we are asking Flash to check if the play head is on the first frame, if so, then move the play head to the very last frame, otherwise move to the previous frame.”

Here’s the code snippet for swipe left:

if(currentFrame == totalFrames)
{
gotoAndStop(1);
}
else
{
nextFrame();
}

Here we are asking flash to check if the play head is on the last frame, if so then go to the first frame, otherwise go to the next frame.

Note: Because we used the “currentFrame” and “totalFrames” properties, and not specific frame numbers, we can add as many frames as we like to our test app, and the code will always work, check out the sample code for more info.

To access code samples, Click Here.
Tutorial files were created using Flash CS5 Professional version 11.0.2.489.

Contents of Archive (2 Files)
loopFramesC.fla (fully commented test app)
loopFrames.txt (info)

Copyright © Shane Hogan
Do not copy this article.

My first iOS App ScaleViz created entirely in ActionScript 3.0, went live July 2011, and shows how music theory relates to your guitar fretboard, you can check it out here http://appstore/scaleviz I have also created Annual Reviews for companies like Mind, FAQ's for Epson UK, taught ECDL and I'm a zombie in the feature film Wasteland UK My hobbies include playing the guitar, watching horror films, astronomy, snorkeling, hypnosis NLP and expanding my knowledge in all areas of programming and graphic design.

Privacy Preference Center

Strictly Necessary Cookies

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

gdpr[allowed_cookies], gdpr[consent_types]

Statistics

This site does not use analytics, vimeo.com is used for displaying tutorial videos and when this Cookie is enabled it may collect data on visits to this site as well as pages read, this cookie is not enabled by default and this should not affect viewing of third party hosted videos by Vimeo.com who describe this cookie as “Vimeo Analytics unique id”. You may however choose to enable this Cookie if you wish, of if you are having issues viewing any videos hosted by Vimeo.com.

vuid

Marketing

We do not use cookies of this type

n/a

Close your account?

Your account will be closed and all data will be permanently deleted and cannot be recovered. Are you sure?