How can I edit this syntax to read Frame Label instead of Scene and Frame Number?

Hi all,

Thanks for checking my post out…

I have the script below which allows the user of a Flash movie use the keyboard to forward/rewind and play/pause.

At the moment the intervals don’t go exactly to where I’ve set them to and many people have suggested I use Frame Labels.

Could someone please help me change the syntax to be able to look for Frame Labels instead of Scenes/Frame Numbers.


import mx.utils.Delegate;

 

var nCheckPoint:Number = -1;

var aCheckPoints:Array = new Array();

aCheckPoints.push( { sScene:"001", nFrame:69 } );

aCheckPoints.push( { sScene:"002_003", nFrame:34 } );

aCheckPoints.push( { sScene:"002_003", nFrame:137 } );

aCheckPoints.push( { sScene:"002_003", nFrame:240 } );

aCheckPoints.push( { sScene:"002_003", nFrame:344 } );

aCheckPoints.push( { sScene:"004_005", nFrame:80 } );

aCheckPoints.push( { sScene:"004_005", nFrame:191 } );

aCheckPoints.push( { sScene:"004_005", nFrame:281 } );

aCheckPoints.push( { sScene:"006", nFrame:80 } );

aCheckPoints.push( { sScene:"007", nFrame:80 } );

aCheckPoints.push( { sScene:"007", nFrame:125 } );

aCheckPoints.push( { sScene:"007", nFrame:150 } );

aCheckPoints.push( { sScene:"007", nFrame:175 } );

aCheckPoints.push( { sScene:"007", nFrame:200 } );

aCheckPoints.push( { sScene:"007", nFrame:217 } );

aCheckPoints.push( { sScene:"007", nFrame:234 } );

aCheckPoints.push( { sScene:"007", nFrame:251 } );

aCheckPoints.push( { sScene:"007", nFrame:302 } );

aCheckPoints.push( { sScene:"007", nFrame:352 } );

aCheckPoints.push( { sScene:"007", nFrame:402 } );

 

var oListener:Object = new Object();

oListener.onKeyDown = Delegate.create(this, onKeyDown);

Key.removeListener(oListener);

Key.addListener(oListener);

 

function onKeyDown():Void

{

   switch(Key.getCode())

   {

   case Key.RIGHT:

      nCheckPoint++

      if(nCheckPoint >= aCheckPoints.length) {

          nCheckPoint = 0;

      }

      GoToCheckPoint(nCheckPoint);

      break;

   case Key.LEFT:

      nCheckPoint--;

      if(nCheckPoint < 0) {

          nCheckPoint = aCheckPoints.length - 1;

      }

      GoToCheckPoint(nCheckPoint);

      break;

   case Key.SPACE:

      play();
	  
	  break;

   case Key.ENTER:

      stop();

      break;
	  	
   default:

      trace("UNHANDLED KEY");

      break;

   }

}

 
function GoToCheckPoint(nValue:Number):Void

{

	var oChkPoint:Object = aCheckPoints[nValue];

	var sScene:String = oChkPoint["sScene"];

	var nFrame:Number = oChkPoint["nFrame"];

	gotoAndStop("sScene", nFrame);

}

Thank you very much,

J


import mx.utils.Delegate;



var nCheckPoint:Number = -1;

var aCheckPoints:Array = new Array();

aCheckPoints.push({nFrame:69});

aCheckPoints.push({  nFrame:34 });

aCheckPoints.push({ nFrame:137 });

aCheckPoints.push({nFrame:240 });

aCheckPoints.push({ nFrame:344 });

aCheckPoints.push({ nFrame:80 });

aCheckPoints.push({ nFrame:191 });

aCheckPoints.push({ nFrame:281 });

aCheckPoints.push({ nFrame:80 });

aCheckPoints.push({ nFrame:80 });

aCheckPoints.push({ nFrame:125 });

aCheckPoints.push({ nFrame:150 });

aCheckPoints.push({ nFrame:175 });

aCheckPoints.push({ nFrame:200 });

aCheckPoints.push({ nFrame:217 });

aCheckPoints.push({ nFrame:234 });

aCheckPoints.push({ nFrame:251 });

aCheckPoints.push({ nFrame:302});

aCheckPoints.push({nFrame:352});

aCheckPoints.push({ nFrame:402});



var oListener:Object = new Object();

oListener.onKeyDown = Delegate.create(this, onKeyDown);

Key.removeListener(oListener);

Key.addListener(oListener);



function onKeyDown():Void {

    switch (Key.getCode()) {

        case Key.RIGHT :

            nCheckPoint++;

            if (nCheckPoint >= aCheckPoints.length) {

                nCheckPoint = 0;

            }

            GoToCheckPoint(nCheckPoint);

            break;

        case Key.LEFT :

            nCheckPoint--;

            if (nCheckPoint < 0) {

                nCheckPoint = aCheckPoints.length - 1;

            }

            GoToCheckPoint(nCheckPoint);

            break;

        case Key.SPACE :

            play();

            break;

        case Key.ENTER :

            stop();

            break;

        default :

            trace("UNHANDLED KEY");

            break;

    }

}
function GoToCheckPoint(nValue:Number):Void {

    var oChkPoint:Object = aCheckPoints[nValue];

    var nFrame:Number = oChkPoint["nFrame"];

    gotoAndStop(nFrame);

}

Something like this

hi paul,

thank you for the reply…

ive tried your version but it didnt work. how would that be able to tell which scene the frame number is in?

ive put the syntax on the first frame of scene 1. is that correct? - do you know what i would need to do then to get this working?

play and stop keys working perfectly though!

thanks again,
j

As for going to specific frames just replace the frame numbers with the labels of those frames instead.

As for navigation scene’s you asked that the script went to frame labels instead of scenes and frame numbers.

hi paul,

thank you, that is mega and works perfectly now!

here is the final syntax i used:


import mx.utils.Delegate;
 
 
 
var nCheckPoint:Number = -1;
 
var aCheckPoints:Array = new Array();
 
aCheckPoints.push({nFrame:"stop001"});
 
aCheckPoints.push({  nFrame:"stop002" });
 
aCheckPoints.push({ nFrame:"stop003" });
 
aCheckPoints.push({nFrame:"stop004" });
 
aCheckPoints.push({ nFrame:"stop005" });
 
aCheckPoints.push({ nFrame:"stop006" });
 
aCheckPoints.push({ nFrame:"stop007" });
 
aCheckPoints.push({ nFrame:"stop008" });
 
aCheckPoints.push({ nFrame:"stop009" });
 
aCheckPoints.push({ nFrame:"stop010" });
 
 
 
var oListener:Object = new Object();
 
oListener.onKeyDown = Delegate.create(this, onKeyDown);
 
Key.removeListener(oListener);
 
Key.addListener(oListener);
 
 
 
function onKeyDown():Void {
 
    switch (Key.getCode()) {
 
        case Key.RIGHT :
 
            nCheckPoint++;
 
            if (nCheckPoint >= aCheckPoints.length) {
 
                nCheckPoint = 0;
 
            }
 
            GoToCheckPoint(nCheckPoint);
 
            break;
 
        case Key.LEFT :
 
            nCheckPoint--;
 
            if (nCheckPoint < 0) {
 
                nCheckPoint = aCheckPoints.length - 1;
 
            }
 
            GoToCheckPoint(nCheckPoint);
 
            break;
 
        case Key.SPACE :
 
            play();
 
            break;
 
        case Key.ENTER :
 
            stop();
 
            break;
 
        default :
 
            trace("UNHANDLED KEY");
 
            break;
 
    }
 
}
function GoToCheckPoint(nValue:Number):Void {
 
    var oChkPoint:Object = aCheckPoints[nValue];
 
    var nFrame:Number = oChkPoint["nFrame"];
 
    gotoAndStop(nFrame);
 
}

ah nice one:)