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
- function loadPosition(frame,hotspots,callback) {
- trace("-----------------------------------------------------------------");
- sequence = mcSequenceContainer.sequence;
- trace("1) loadPosition: "+frame+ " With hotspots: "+hotspots+" Current frame: "+sequence._currentframe);
- sequence.onEnterFrame = function() {
- // When final frame is reached stop play and load hotspots and or callback
- if(this._currentframe == frame) {
- trace("2) Final frame reached.");
- if(hotspots != null) {
- trace("3) Loading hotspots...");
- loadHotspots(hotspots);
- }
- if(callback != null) {
- trace("4) Callback not null");
- callback();
- }
- this.stop();
- delete this.onEnterFrame;
- }
- else {
- // If frame is greater play sequence forwards
- if(this._totalframes - frame >= frame + (this._totalframes - frame)) {
- trace("Totalframes - frame: "+this._totalframes - frame+" Frame + totalframes - frame: "+frame + (this._totalframes - frame));
- trace("Forwards: "+this._currentframe+" "+frame);
- // Check currentframe doesn't exceed number of frames
- if(this._currentframe + 1 > this._totalframes) {
- // Reset to first frame and continue
- this.gotoAndStop(1);
- }
- else {
- // Increment frame
- this.gotoAndStop(this._currentframe + 1);
- }
- }
- // If frame is less than play sequence backwards
- else if(this._totalframes - frame <= frame + (this._totalframes - frame)) {
- trace("Totalframes - frame: "+(this._totalframes - frame)+" Frame + totalframes - frame: "+(frame + (this._totalframes - frame)));
- trace("Backwards: "+this._currentframe+" "+frame);
- // Ensure currentframe doesn't become a negative number
- if(this._currentframe - 1 < 1) {
- // Reset to first frame and continue
- this.gotoAndStop(this._totalframes);
- }
- else {
- // Decrement frame
- this.gotoAndStop(this._currentframe - 1);
- }
- }
- }
- // DEV: trace("Current frame: "+sequence._currentframe+" Target frame: "+frame);
- }
- }
Expand|Select|Wrap|Line Numbers
- if(this._totalframes - frame >= frame + (this._totalframes - frame))
Chromis