Connecting Tech Pros Worldwide Help | Site Map

How to work out whether to go forward frames or backwards frames?

Member
 
Join Date: Jan 2008
Posts: 113
#1: Dec 23 '08
Hi,

I'm creating virtual tour of a house, the part I am working on at the moment involves a 360 spin view of the house (a series of 36 flat frames). Each corner of the house has a hotspot so that the user may click to navigate to that corner. I have completed the code to get the house to spin to the correct hotspot when the user clicks on a hotspot but where I'm struggling is working out the correct code so that if you are on position 1 and want to get to position 4 the house will spin backwards not forwards all the way through points 2 and 3 to get to 4.

Here is my code so far:

Expand|Select|Wrap|Line Numbers
  1. function loadPosition(frame,hotspots,callback) {
  2.     trace("-----------------------------------------------------------------");    
  3.     sequence = mcSequenceContainer.sequence;
  4.     trace("1) loadPosition: "+frame+ " With hotspots: "+hotspots+" Current frame: "+sequence._currentframe);
  5.  
  6.     sequence.onEnterFrame = function() {
  7.  
  8.         // When final frame is reached stop play and load hotspots and or callback
  9.         if(this._currentframe == frame) {
  10.             trace("2) Final frame reached.");
  11.             if(hotspots != null) {
  12.                 trace("3) Loading hotspots...");                
  13.                 loadHotspots(hotspots);
  14.             }
  15.             if(callback != null) {
  16.                 trace("4) Callback not null");
  17.                 callback();
  18.             }
  19.             this.stop();
  20.             delete this.onEnterFrame;
  21.         }
  22.         else {
  23.             // If frame is greater play sequence forwards
  24.             if(this._totalframes - frame >= frame + (this._totalframes - frame)) {
  25.                 trace("Totalframes - frame: "+this._totalframes - frame+" Frame + totalframes - frame: "+frame + (this._totalframes - frame));
  26.                 trace("Forwards: "+this._currentframe+" "+frame);
  27.  
  28.                 // Check currentframe doesn't exceed number of frames
  29.                 if(this._currentframe + 1 > this._totalframes) {
  30.                     // Reset to first frame and continue
  31.                     this.gotoAndStop(1);
  32.                 }
  33.                 else {
  34.                     // Increment frame
  35.                     this.gotoAndStop(this._currentframe + 1);                
  36.                 }
  37.  
  38.             }
  39.  
  40.             // If frame is less than play sequence backwards
  41.             else if(this._totalframes - frame <= frame + (this._totalframes - frame)) {
  42.                 trace("Totalframes - frame: "+(this._totalframes - frame)+" Frame + totalframes - frame: "+(frame + (this._totalframes - frame)));
  43.                 trace("Backwards: "+this._currentframe+" "+frame);
  44.  
  45.                 // Ensure currentframe doesn't become a negative number
  46.                 if(this._currentframe - 1 < 1) {
  47.                     // Reset to first frame and continue
  48.                     this.gotoAndStop(this._totalframes);
  49.                 }
  50.                 else {
  51.                     // Decrement frame
  52.                     this.gotoAndStop(this._currentframe - 1);                
  53.                 }
  54.  
  55.             }            
  56.         }
  57.         // DEV: trace("Current frame: "+sequence._currentframe+" Target frame: "+frame);    
  58.     }
  59. }
  60.  
The code of interest is to the test statement, which im trying to get to work out how many frames it is in each direction to the target frame, then based on that result decide which direction to go:

Expand|Select|Wrap|Line Numbers
  1. if(this._totalframes - frame >= frame + (this._totalframes - frame))
  2.  
Thanks,

Chromis
Reply