Monday, May 14, 2012

[Action Script] var myInterval = setInterval problem how to stop it on dunamic objects? May,2012

Iv got this problem, in a function im creating dynamicaly many objects on the stage of My_class and for every object im running a setInterval with a function declaration to move that object:
var myInterval = setInterval( function() { moveObject(instance); }, 50 );

when the object reaches some point i would like to delete it and stop the setInterval. The problem is that i cannot use clearInterval from moveObject function since i have no acces to var myInterval thats declared in another function and i cannot declare myInterval out side of that function becouse then the setInterval for other objects stops and they stop moving. Any1 can help me with some solution :S ? Im braindead by now :(
example:
ActionScript Code: package {    public class blabla    {        public function asd()        {            // constructor code        }        function gameHandler(evt:Event):void        {            if (getTimer() >= interval)            {                releaseObject();                interval +=  1000;            }        }        function releaseObject():void        {            var ClassReference:Class = getDefinitionByName("MyClass") as Class;            var instance:Object = new ClassReference();            var myInterval = setInterval(function() { moveObject(instance); },50);        }        function moveObject(obj:Object):void        {            obj.x +=  1;            obj.y -=  10;            if (obj.x >= 0)            {            }        }    }}
Thanks in advance,
kni4x
var myInterval = setInterval problem how to stop it on dunamic objects?

Related Post



0 comments: