FORUMS: list search recent posts

passing variables through setInterval

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
passing variables through setInterval
on Aug 8, 2007 at 8:05:51 pm

Below is my code for tweening a MC to random points on the Y-axis. It works when the variable ranTime is replace with a hard-coded number. And it works the first time through the function newPos(), with the variable being passed in the usual manner. But once the setInterval starts to call the newPos function, I cant figure a way to pass the ranTime variable to it.

Is there a way to do this or am I looking at doing this another way all together?

Many thanks

var ranTime:Number=600;

import mx.transitions.Tween;
import mx.transitions.easing.*;

function newPos(ranTime):Void{
var currentPos = obj_mc._y;
var ranPos:Number = Math.round(Math.random()*300)-50;
var yPosT:Tween = new Tween(obj_mc, "_y", Regular.easeIn, currentPos, ranPos, ranTime, true);

resetPos = setInterval(this, "newPos", 600);

function newTime():Void{
ranTime = Math.round(Math.random()*600);



Return to posts index

Re: passing variables through setInterval
on Aug 8, 2007 at 8:06:34 pm

forgot to subscibe

Return to posts index

Paul Fechtmeister
Re: passing variables through setInterval
on Aug 11, 2007 at 9:30:46 pm

take this with a grain of salt.. but noone replied so..

you might be able to use onEnterFrame....

If I could see the whole .fla that might help but I'm not claiming to be an actionscript expert.. .by the way is this 2.0 or 3.0 actionscript?


Return to posts index

Re: passing variables through setInterval
on Aug 23, 2007 at 7:09:25 am

Hey there, just to follow up. Turns out I was able to pass the variable into the function as described in an earlier post. However, it seems the value of the variable is stored in setInterval only the forst time the setInterval is called, not on each recurring event triggered by the setInterval.

i ended up building a custom timer using the getTimer and if...else that did the trick. Hope this enlightens somebody in the future...


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved