How do I loop back from the first frame to the last frame?

Hi there,
I'm currently working on the framework for a product viewer.
I have:
a movie clip called 'viewer_mc' which contains the images take from different angles of the product. The actionscript generates a script on the last frame of this that returns it to frame 1.
a button instance called 'autoplay_btn' which plays through the movie clip from whatever the current frame is, and stops on frame 1.
a left and right button which serve to move the movie clip frame, to give the appearance that the product is rotating.
I have succeeded in getting it to:
have the movie clip play through once, return to frame 1 and stop.
have the buttons return functions when held down, that move the frame in the movie clip using nextFrame and prevFrame commands. The right button successfully loops round to frame 1 and continues functioning to give the appearance of continual rotation.
The last problem I am experiencing is getting the left button to act in the corresponding manner, going from the first frame to the last and continuing to function.
Here is my actionscript so far:
import flash.events.MouseEvent;
var lastFrame:Number = viewer_mc.totalFrames;
var thisFrame:Number = viewer_mc.currentFrame;
var backFrame:Number = viewer_mc.currentFrame-1;
1. This is the part that gets it to play through once before returning to the first frame. I think perhaps the problem I am experiencing is because of the 'viewer_mc.addFrameScript(lastFrame-1, toStart)' part i.e. although I'm holding the left button, its returning to this script and therefor getting bounced back immediately to the first frame. However, there is no flicker on the screen which you might expect if this were the case
Note - as this is a generic product viewer which I can use as a template I am using lastFrame etc. as opposed to typing the value in
function toStart (){
          viewer_mc.gotoAndStop(1);
viewer_mc.addFrameScript(lastFrame-1, toStart);
2. This is the functionality for the autoplay_btn that will play through a rotation / return the viewer to the initial (frontal) view of the product (frame 1).
autoplay_btn.addEventListener(MouseEvent.MOUSE_DOWN, autoplay);
function autoplay (ev:MouseEvent):void{
          var startFrame:Number = viewer_mc.currentFrame;
          viewer_mc.gotoAndPlay(startFrame);
3. This is the functionality of the right button, which when held, moves the movie clip to the next frame via the 'rotateRight' function based on the 'nextFrame' command. It loops back round to the first frame due to the 'viewer_mc.addFrameScript(lastFrame-1, toStart)' script generated on the last frame of the movie clip, as is desired.
right_btn.addEventListener(MouseEvent.MOUSE_DOWN, rightDown);
function rightDown(e:Event){
    stage.addEventListener(MouseEvent.MOUSE_UP,stoprightDown); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
    addEventListener(Event.ENTER_FRAME,rotateRight); //while the mouse is down, run the tick function once every frame as per the project frame rate
function stoprightDown(e:Event):void {
    removeEventListener(Event.ENTER_FRAME,rotateRight);  //stop running the tick function every frame now that the mouse is up
    stage.removeEventListener(MouseEvent.MOUSE_UP,stoprightDown); //remove the listener for mouse up
function rotateRight(e:Event):void {
    viewer_mc.nextFrame();
4. This is the functionality of the left button, which when held, moves the movie clip to the prev frame via the 'rotateRight' function based on the 'prevFrame' command. And this is where the problem lies, as although it works for getting the movieclip back to frame 1, it does not loop round to the last frame and continue functioning, as is wanted.
left_btn.addEventListener(MouseEvent.MOUSE_DOWN, leftDown);
function leftDown(e:Event){
    stage.addEventListener(MouseEvent.MOUSE_UP,stopleftDown); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
    addEventListener(Event.ENTER_FRAME,rotateLeft); //while the mouse is down, run the tick function once every frame as per the project frame rate
function stopleftDown(e:Event):void {
    removeEventListener(Event.ENTER_FRAME,rotateLeft);  //stop running the tick function every frame now that the mouse is up
    stage.removeEventListener(MouseEvent.MOUSE_UP,stopleftDown); //remove the listener for mouse up
I'd imagine it is probably my logic for this part that is really letting me down - I can do a similar function in actionscript 2, but am trying to learn actionscript 3 just to move with the times as it were, and struggling a bit. Still this is only a few days in!
function rotateLeft(e:Event):void{
          if(thisFrame==1){
                    gotoAndStop(viewer_mc.totalFrames-1);
          } else{
          viewer_mc.prevFrame();
Any help you can give me would be gratefully received. For an example of the effect I am trying to achieve with the autoplay button etc. I recommend:
http://www.fender.com/basses/precision-bass/american-standard-precision-bass

Thanks for getting back to me.
Here's the code without my comments / explanations:
import flash.events.MouseEvent;
import flash.events.Event;
var lastFrame:Number = viewer_mc.totalFrames;
var thisFrame:Number = viewer_mc.currentFrame;
var backFrame:Number = viewer_mc.currentFrame-1;
function toStart (){
          viewer_mc.gotoAndStop(1);
viewer_mc.addFrameScript(lastFrame-1, toStart);
//last image of viewer_mc = first image of viewer_mc
autoplay_btn.addEventListener(MouseEvent.MOUSE_DOWN, autoplay);
function autoplay (ev:MouseEvent):void{
          var startFrame:Number = viewer_mc.currentFrame;
          viewer_mc.gotoAndPlay(startFrame);
right_btn.addEventListener(MouseEvent.MOUSE_DOWN, rightDown);
function rightDown(e:Event){
    stage.addEventListener(MouseEvent.MOUSE_UP,stoprightDown); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
    addEventListener(Event.ENTER_FRAME,rotateRight); //while the mouse is down, run the tick function once every frame as per the project frame rate
function stoprightDown(e:Event):void {
    removeEventListener(Event.ENTER_FRAME,rotateRight);  //stop running the tick function every frame now that the mouse is up
    stage.removeEventListener(MouseEvent.MOUSE_UP,stoprightDown); //remove the listener for mouse up
function rotateRight(e:Event):void {
    viewer_mc.nextFrame();
left_btn.addEventListener(MouseEvent.MOUSE_DOWN, leftDown);
function leftDown(e:Event){
    stage.addEventListener(MouseEvent.MOUSE_UP,stopleftDown); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
    addEventListener(Event.ENTER_FRAME,rotateLeft);//while the mouse is down, run the tick function once every frame as per the project frame rate
function stopleftDown(e:Event):void {
    removeEventListener(Event.ENTER_FRAME,rotateLeft);  //stop running the tick function every frame now that the mouse is up
    stage.removeEventListener(MouseEvent.MOUSE_UP,stopleftDown); //remove the listener for mouse up
function rotateLeft(e:Event):void{
          viewer_mc.prevFrame();
The definition of the rotateLeft function is where the problem lies I think - I've taken out my poor attempts at doing the logic from the previous post. If I were to write it out long-hand the statement I want to write is: 'If you get to frame 1 and function rotateLeft is called go to the end of the movie clip'.
The reason I have to use the viewer_mc.totalFrames-1 definition in the addFrameScript call is the addFrameScript function is 0 based i.e. if you want to call frame 1 of the movieclip you have to return a value of 0 in the addFrameScript (or such is my understanding of it anyway). As such, the last image in the movie clip will need to be the view obtained at 360 degree rotation, which is of course the same view as at 0 degree rotation. As a consequence, the last frame in the movie clip is superfluous for the user, but necessary for the overall effect to be achieved. And, in addition, to keep up the effect of a 360 degree view when the rotateLeft function is called it needs to skip that last frame to go to the lastFrame-1 (or totalframes-1), or in other words, the view of the image prior to completing the full 360 rotation.
the variables thisFrame and lastFrame are defined at the very top of the script. Like you said they might need to be defined or called on again elsewhere.

Similar Messages

  • I have version 3.6.16 and when I login to my hotmail account, and type the first letter of the email address, a drop down box appears with my hotmail address and I can choose it from that box with a click. How do I get version 4 to do this? Thanks.

    I have version 3.6.16 and when I login to my hotmail account, and type the first letter of the email address, a drop down box appears with my hotmail address and I can choose it from that box with a click.
    How do I get version 4 to do this?
    Thanks.

    The new but not-ready-for-prime-time autocomplete method searches for matches that contain the entered text, not just ones that begin with the string. Your options are:
    1) type in longer strings that narrow the search
    2) use an add-on to search just the beginnings:
    https://support.mozilla.org/en-US/questions/1037469
    3) install an older version of TB:
    http://ftp.mozilla.org/pub/mozilla.org/thunderbird/releases/

  • How can I remove the page number from the first page of the document that is the cover page?

    How can I remove the page number from the first page of the document that is the cover page?

    If you open the Pages panel, (Window>Pages) you will see thumbnails of your master pages and your document pages. In new documents, there is usually a master called A-Master and one called None. If you drag the thumbnail of the None master onto the thumbnail of a document page, it will apply that master to that page. Presumably, you have made your page numbers on A-Master, so this will usually do the trick. If you have elements on A-Master that you need on the first page, but just not the page number, you can duplicate A-Master (which, by default will give you B-Master, but you can change the names if you like) and remove the page number on the duplicate and apply that to the document page.
    It might also be worth noting that you can apply master pages in the fly-out of the Pages panel. Go to the fly-out triangle and go down to Apply Master to Pages…, then select a master to apply and the range of pages (1-8 will give you all 8, 1, 3, 5, 7 will be the odds, 1-3, 4, 6-8 if you want continuous ranges and individual pages).

  • How do I delete an email address from the dropdown that appears after I type the first letter of the recipiants address in the To: bar.

    When I open compose and type the first letter of the recipients address in the To: bar a dropdown appears with a listing of the email addresses I have sent messages to in the past as well as addresses of my contacts list.
    How do I delete an address from this dropdown?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

  • I am trying to copy and paste a story from a blog.  I can only view the first page on the Pages app.  How do I see the rest of the pages?

    I am trying to copy and paste a story from a blog.  I can only view the first page on the Pages app.  How do I see the rest of the pages?

    Thank you.  That helped in the first step.  I was able to copy text onto multiple pages.
    Now I can't get the pictures to copy.  How do I get my pictures to copy?
    Also once the blog page is on pages, how do i make changes to it?
    This my story and the page I am trying to copy.
    http://www.city-data.com/forum/tennessee/359683-going-off-grid-east-tennessee.ht ml
    Thanks so much
    Lisa(writing) and Mike trying to get it right.

  • How to get the first day in the month from a domain date ?

    Hi,
    I like to know how to get the first day in the month from a domain date?
    Thanks
    Stephen

    Hi Gokul...
    Instead of using the funtion module you can just write the 3 statements of code to get the first day of the week.
    Its similar to the above one but instead of writing case statement you can achive the following.
    data : w_res type i,
             w_data type d,
    w_res = w_date mod 7.
    w_date = w_date - w_res.
    write w_date.
    This works.
    Regards,
    Siddarth

  • HT201304 How do I change back from UK iTunes to Australia on the iPad!!

    How do I change back from UK iTunes to Australia on the iPad!! I changed it by accident and can't find where to change it back on the iPad! Syncing to computer didn't help.

    Follow this link, which will walk you the steps:  http://support.apple.com/kb/ht1311

  • Plz tell me how I can get back from the recovery mode to my normal mode without lossing data ... actually I was trying to update ios 7 in my 4s so then mobile stuck into recovery mode...plz help?

    plz tell me how I can get back from the recovery mode to my normal mode without lossining data...I stuck in this mode while I was try to update ios 7 in my 4s

    If it's in recovery mode, anything on the phone is already gone.  Restore the phone using iTunes, then restore it from your last backup. If you've been backing up on a regular basis as intended, you won't lose anything except what's changed since the last backup.

  • I deleted a specific website from the "History" and used "forget this site" but it still shows up when I type the first letter of the site. How do I delete it?

    I am not computer savvy. I don't want to clear all my history, just one specific site. I deleted it, its cookies, passwords and everything and when I type the first letter of the website in, it shows up as one of the options for websites. I need to delete it, but how?

    Maybe these will help?
    *http://kb.mozillazine.org/Deleting_autocomplete_entries
    *[[Remove websites from the Awesome Bar suggestions]]
    It's possible the website is in your bookmarks and when you type in some letters in the Location Bar that match that bookmark, it is coming up from there. See [[Search your bookmarks, history and tabs with the Awesome Bar]] for details on changing your Location Bar settings in your [[Options Window - Privacy panel|privacy settings]].

  • How can I roll back from the latest update - hate it!

    I can't get the quick WYSIWYG bar to show up. I want my old version back. How can I roll back?

    I can't get the quick WYSIWYG bar to show up.
    Not sure what that means.   Can't you switch to Live View or Design View ? See screenshot.
    In Creative Cloud desktop app, select Filters & Versions > Previous Version.
    Nancy O.

  • How do I transfer files from my hard drive to the MacBook?

    I am a new Mac user and I transferred all of my files that were on my PC to an external hard drive in order to transfer them to the macbook.  However once I plugged in the hard drive to my mac, I don't understand how to transfer my files over.  There's no "My Computer" on a Mac so I don't know how to do it. Step by step instructions please!  Thank you so much!!!!!!!!

    milkaballet wrote:
    Once yes but I turned it off! Oh no! Whats next?
    It sounds like you got a prompt like this:
    Clicked Use as Backup Disk, then got this one:
    and clicked Erase.  If so, your data has been deleted (not actually erased, regardless of what the message says, although if a backup got started, some of it may have been erased).
    But first let's find out what's actually what.
    Open the Disk Utility app (in your Applications/Utilities folder).  Click the top line of the drive, similar to this:
    then click the line for the volume (indented under the main one):
    Report back with the Partition Map Scheme from the first one, and the Format for the second.

  • Case: When trying t work in a second desktop, a program cannot be used if open in the first desktop. The screen just moves back to the first deskt

    When I try to work in a second desktop, a program cannot be used if already open in the first desktop. The screen just moves back to the first desktop. Anybody else have this issue?

    Whether or not this behavior occurs depends upon various preference settings and upon how you try to access the application in question.  Personally, I like to organize my desktops according to project, so I regularly have windows from the same application spread out over several desktops. No problem.
    For example, I have a Safari window in Desktop 1 and I want a Safari window in desktop 2. If, while in desktop 2, I bring Safari to the front by clicking on the Dock icon, I can open a new window in the usual ways. I could also just control-click on the Safari icon in the dock to get a new window in desktop 2. 
    (The only application that is a little weird in this regard is Finder. You have to do the control-click on it or it will always switch to a space with a window open.)
    To make all this occur, I have Safari assigned to no desktops (control-click on Safari icon, then on Options) and in Mission Control preferences (in System Preferences) I have "When switching to an application..." UNchecked.
    (Note that, with these settings, if an application is already in front and you click on its icon - or click twice on the icon if the applcation is not in front - the OS will assume you are looking for another open window and will switch spaces to give you one.)
    Hope this helps.
    charlie

  • Hard drive on my mac died, installed new hard drive.  When I try to sync my phone for the first time, will the computer wipe all the songs, photos, ibooks from my phone?

    hard drive on my mac died, installed new hard drive.  When I try to sync my phone for the first time, will the computer wipe all the songs, photos, ibooks from my phone?

    Yes because that information is not located on the hard-drive of your new mac! If it is purchased content from the store, than this issue isn't as bad as it looks!
    Here is a link explaining how to get your previously purchased content back:
    http://support.apple.com/kb/HT2519
    You also want to authorize your Apple ID account on the computer by following these instructions as well:
    http://support.apple.com/kb/PH1730
    Basically this link explains to go to the top left corner of your screen where you will see file, edit, view etc! Click on Store in that section and click on authorize this computer, also you want to make sure that the computer will not automatically sync by going to iTunes in the top left corner, just to the right of the apple symbol if iTunes is selected, and go to prefrences, and here you will see back up! Right under the back-ups has an option explaining to prevent devices from automatically syncing which is good cause you may be able to transfer your purchases from there which will put your content into the computer, and if that happens than we don't lose anything
    Hopefully I was of some help:)

  • In Pages, when I hit the return button, the first letter on the new line is not capitalises. How do I get it to capitalise automatically?

    In Pages, when I hit the return button, the first letter on the new line is not capitalises. How do I get it to capitalise automatically?

    Right click the Back button and choose the page you want to go to from the list.
    '''N.B.''' I noticed that your Flash installation is out of date which exposes your system to attack. See: http://www.adobe.com/support/security/bulletins/apsb11-18.html<br><br>
    Update via http://get.adobe.com/flashplayer/

  • How to get data back from an action ?

    Hello,
    Would it be possible to get data back from an action (out of the question EO_MESSAGE & ET_FAILED_KEY )?
    For example we got an order with order positions and we need a "function" to e.g. count all positions. Because of Performance the function should not be processed each time the order is changed, read or a position is added. Instead the function should be processed only if it was called explicitly.
    Is it possible to create a kind of action which is actually counting all entries and export the number of them?
    How to mark a parameter in is_parameters as exporting?
    Is this just done by (naming-) convention?
    What is the preferred way to have “methods” with returning/exporting values?
    Regards,
    Lorenz

    Hello Lorenz,
    As you have already figured out , the Action API provides you with only the messages and failed keys if any.
    Post action execution , you can always execute a retrieve or retrive by association , to get the latest buffer snapshot , which of course would include the changes that you have made in your action.
    If you want to ensure that users have explict control on execution of your "fucntion", then of course , you should model it as an action on the BO.
    The parameter is_parameters is an IMPORTING parameter. You CANNOT use it to export anything back from the action. For importing ,  you can of course have any structure to use as the is_paramaters , which you model as the action parameter structure which modelling your BO action.
    From an external entity the only way to interact with a BO is by consuming the BO services and you are bound by the BOBF standard interfaces. Any and all data you require needs to be modelled as node attributes ( persistent or transient ) and fetched using the RETRIEVE, RETRIEVE_BY_ASSOCIATION or QUERY services.
    Regards,
    Indranil.

Maybe you are looking for