rogue interval will not clear

  • johnnygod
  • Novice
  • Novice
  • johnnygod
  • Posts: 25

Post 3+ Months Ago

Is a specific reason why this interval will not clear? or why functions called with setInterval may get stuck and not clear? In the following: the video plays in slowmotion when pressing the play_mc , but continues to play slowmotion even onRelease.

Code: [ Select ]
var myConnection:NetConnection=new NetConnection;
myConnection.connect(null);

var myStream:NetStream=new NetStream(myConnection);

this.video.attachVideo(myStream);

myStream.play("JackAssSpecial.flv");


//  Loop Playback

myStream.onStatus = function(infoObject:Object){
if (infoObject.code =="NetStream.Play.Stop"){
    myStream.seek(0);
    myStream.pause(false);
    delete _root.play_mc.clearInterval(ID1);
    }
}

//    handlers      


_root.play_mc.onPress=function(){
    myStream.pause(true);
    beginInterval();
}
_root.play_mc.onRelease=function(){
    this.clearInterval(ID1);
    myStream.pause(false);
}
_root.stop_mc.onPress=function(){
    _root.clearInterval(ID1);
}


//   functions  

function beginInterval(){
    var rate:Number=150;
    var ID1=setInterval(this,"slowMotion",rate);
}
    
    
function slowMotion():Void{
    var T:Number=myStream.time;
    myStream.seek(T+0.06);
}
  1. var myConnection:NetConnection=new NetConnection;
  2. myConnection.connect(null);
  3. var myStream:NetStream=new NetStream(myConnection);
  4. this.video.attachVideo(myStream);
  5. myStream.play("JackAssSpecial.flv");
  6. //  Loop Playback
  7. myStream.onStatus = function(infoObject:Object){
  8. if (infoObject.code =="NetStream.Play.Stop"){
  9.     myStream.seek(0);
  10.     myStream.pause(false);
  11.     delete _root.play_mc.clearInterval(ID1);
  12.     }
  13. }
  14. //    handlers      
  15. _root.play_mc.onPress=function(){
  16.     myStream.pause(true);
  17.     beginInterval();
  18. }
  19. _root.play_mc.onRelease=function(){
  20.     this.clearInterval(ID1);
  21.     myStream.pause(false);
  22. }
  23. _root.stop_mc.onPress=function(){
  24.     _root.clearInterval(ID1);
  25. }
  26. //   functions  
  27. function beginInterval(){
  28.     var rate:Number=150;
  29.     var ID1=setInterval(this,"slowMotion",rate);
  30. }
  31.     
  32.     
  33. function slowMotion():Void{
  34.     var T:Number=myStream.time;
  35.     myStream.seek(T+0.06);
  36. }
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

I'm amazed it works at all. :scratchhead:

If you're wondering, setInterval returns a Number datatype.

Code: [ Select ]
var intervalID:Number;

var starter:Function = function():Void {
  intervalID = setInterval( functionObject, timing, paramatersSentToFunctionObject );
}
  1. var intervalID:Number;
  2. var starter:Function = function():Void {
  3.   intervalID = setInterval( functionObject, timing, paramatersSentToFunctionObject );
  4. }
  • johnnygod
  • Novice
  • Novice
  • johnnygod
  • Posts: 25

Post 3+ Months Ago

thanks, joebert,

Do you mean the syntax is incorrect and should be:

function beginInterval():Void{
var rate:Number=150;
ID1=setInterval(this,"slowMotion",rate);
}
  • johnnygod
  • Novice
  • Novice
  • johnnygod
  • Posts: 25

Post 3+ Months Ago

Turns out __

it's not this.clearInterval but,

_root.play_mc.onRelease=function(){
clearInterval(ID1);
myStream.pause(false);
}
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

I'm still amazed it does anything.

This line in particular boggles my mind, specially when you consider there's no sign of that third paramater being used in the method that's being passed where the interval timing should be.
Code: [ Select ]
setInterval(this,"slowMotion",rate);


Oh well, if it works, whadduya do ? :lol:
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

i don't think he actually understood correctly the help from flash (this if he read it in the first place):
Code: [ Select ]
Usage:
setInterval(functionName, interval [, param1, param2, ..., paramN])

Parameters:
functionName A function name or a reference to an anonymous function.

interval: The time in milliseconds between calls to the functionName parameter.

param1, param2, ..., paramN Optional parameters passed to the function or methodName parameter.
  1. Usage:
  2. setInterval(functionName, interval [, param1, param2, ..., paramN])
  3. Parameters:
  4. functionName A function name or a reference to an anonymous function.
  5. interval: The time in milliseconds between calls to the functionName parameter.
  6. param1, param2, ..., paramN Optional parameters passed to the function or methodName parameter.
  • johnnygod
  • Novice
  • Novice
  • johnnygod
  • Posts: 25

Post 3+ Months Ago

IceCold guru,

Can you recommend a preferred implementation of setInterval - I have read a number of variations:

Code: [ Select ]

setInterval("functionName", duration)
  1. setInterval("functionName", duration)


or assign a variable name:

Code: [ Select ]

intervalId = setInterval("functionName", duration);
  1. intervalId = setInterval("functionName", duration);



I found that the above syntax often did not work unless written (as stated in Actionscript 2.0 language Reference) with the "THIS" :

Code: [ Select ]

intervalId = setInterval(this, "functionName", duration);
  1. intervalId = setInterval(this, "functionName", duration);


or written as a method as in Flash Hacks:

Code: [ Select ]

var puck:MovieClip=drawBall(puck,20,200);
puck.intervalMover=mover    // a function that moves the puck
puck.interval=setInterval(puck, "intervalMover",duration);
  1. var puck:MovieClip=drawBall(puck,20,200);
  2. puck.intervalMover=mover    // a function that moves the puck
  3. puck.interval=setInterval(puck, "intervalMover",duration);


and I am trying to change the duration of an interval as it operates, is this possible? assign a rate variable to a setInterval and change it with varying value of a slider control? Can you offer a simpler solution?


[/code]
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Used to execute without need of returned value for later call:
Code: [ Select ]
setInterval("functionName", duration)


Used so that you can call on the success of the function:
Code: [ Select ]
intervalId = setInterval("functionName", duration);


Same thing, only setting it to an object's property:
Code: [ Select ]
puck.interval=setInterval(puck, "intervalMover",duration);


As for the method of using setInterval, all three are valid for separate instances. Can you be specific as to what you wish to do with your interval? Your code up top needs an overhaul...

Try clicking here for a good resource which may straighten out its different forms of use for you.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.