Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
- Original Message - From: "Kalani Bright" <[EMAIL PROTECTED]> To: Sent: Thursday, March 01, 2007 4:55 AM Subject: RE: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. > 1) setInterval is not accurate. Try moving the window around and see if the > function gets called when it's supposed to. Keep a timer and compare the > interval call to the time over say a minute to 2 minute period. You could > be off by several or more seconds, and if you move the window around like > crazy your 1 second interval could be called 7 seconds later. This is a player problem, not a setInterval problem. Same thing happens when you use onEnterFrame. Noone said setInterval is accurate, I think it even states in the docs it's not accurate. If interval is less than the SWF file's frame rate (for example, 10 frames per second [fps] is equal to 100 millisecond intervals), the interval function is called as close in time to the value of interval as possible. Executing long, memory-intensive scripts during an interval causes delays. If the function being called initiates a change to visual elements, you should use the updateAfterEvent() function to make sure that the screen refreshes often enough. If interval is greater than the SWF file's frame rate, the interval function is called only after interval has expired and the playhead has entered the next frame; this minimizes the impact each time the screen is refreshed. > 4) Even with a reference to the interval the interval may not always be > deleted. Sorry, it's not. Do some tests. This is especially the case if > you use delegates with your setinterval. The management problem for > performance gets even worse. Making sure you delete and clear everything. > But in my experience the intervals don't clear like they should even went > set to self-destruct. So far I never had issues with clearing a setInterval. But that might be because I stick to the rules I mentioned earlier. I do make sure to test them extensively when I do use them. > 5) The 3 parameter setinterval call is not for scope, its for the object > containing the method you want to call, if thats what you meant by scope. Yup, my worthing wasn't correct. > The object could be removed and the interval continue to be called. Not if you make sure to clean up properly. > PS -(Try and be helpful rather than sticking your nose up at people) It's my nose, I'll do with it whatever I please, tyvm.. regards, Muzak ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
You can use a singleton. It's just important that the intervals be managed in a single location. _root can be used by as1 or as2 programmers. AS3 supports a document class and support for inner classes which means (through some creative engineering) singletons as well, no need for root. 1) setInterval is not accurate. Try moving the window around and see if the function gets called when it's supposed to. Keep a timer and compare the interval call to the time over say a minute to 2 minute period. You could be off by several or more seconds, and if you move the window around like crazy your 1 second interval could be called 7 seconds later. 2) Create your own class which does this. 3) onEnterFrame to check intervals (in a singleton) or single instance class, or root! 4) Even with a reference to the interval the interval may not always be deleted. Sorry, it's not. Do some tests. This is especially the case if you use delegates with your setinterval. The management problem for performance gets even worse. Making sure you delete and clear everything. But in my experience the intervals don't clear like they should even went set to self-destruct. 5) The 3 parameter setinterval call is not for scope, its for the object containing the method you want to call, if thats what you meant by scope. The object could be removed and the interval continue to be called. 6) Why go through all this headache when you can easily write your own interval class which is accurate and deletes itself when told? *regards* Kalani PS -(Try and be helpful rather than sticking your nose up at people) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Muzak Sent: Wednesday, February 28, 2007 7:04 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. As a posted last week or something, there's a few things to keep in mind when using setInterval - clear interval before setting it - always use this syntax setInterval(scope, "method", interval) - and never use this syntax setInterval(function, interval) - keep a reference to the interval - remove it when done If things go haywire, you're doing something wrong and you probably forgot one of the above. If you're referring to everything using _root, code in the main timeline and advise others to do so, please join the flashnewbie list http://chattyfig.figleaf.com/mailman/listinfo/flashnewbie regards, Muzak - Original Message - From: "Kalani Bright" <[EMAIL PROTECTED]> To: Sent: Thursday, March 01, 2007 3:15 AM Subject: RE: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. > When I was using AS2 I found that no matter what there were always memory > leaks with set interval and even after I explicitly tell Flash to remove the > interval it never got removed... > > So even though I never wrote it I would offer the following advice, which is > to *almost* not use setInterval at all. Just use it once, for the root... > 1) Move all functionality for intervals to a script on the root > 2) The root is always available, and you won't have intervals all over the > place > 3) Create only one interval for a function on the root which is responsible > for calling functions > 4) The function should get the same sort of information as whats required by > setInterval. > 5) Call functions based on the timer. Time since movie started. A little > math should test if the objects which are registered with your script should > be called again. I would also recommend enabling this function to support > something like "call this function X times every 1000 ms). Rather than > call this object every 1000ms. That way you can delete it automatically if > its reached that number. > 6) That script keeps information on what intervals are set > 7) The script periodically checks for objects which no longer exists and > deletes them from the interval array. > 8) Intervals are set or removed by calling a root function. Use the > delegate class to say which function gets the interval callback and also > pass a reference to the object. > > Good luck, > > Kalani > > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop. Thanks All!
Thanks all! I have the code working now. I will be sure to hang on to the replies, so I can have them for reference. THANKS. Paul Vdst - Original Message - From: "Omar Fouad" <[EMAIL PROTECTED]> To: Sent: Wednesday, February 28, 2007 9:02 PM Subject: Re: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. > Link Updated > :D > http://www.proeye.net/omarfouad/myClasses/SetTimer.rar > > > On 3/1/07, Omar Fouad <[EMAIL PROTECTED]> wrote: > > > > well I've actually created a class called SetTimer.as that executes a > > function after a given time in seconds and can loop the function many times > > u want.. > > > > see just put the class in the same directory of the fla and use: > > > > import SetTimer; > > var myTimer:SetTimer = new SetTimer(2, function () {myFunction();}, 5); > > > > where "2" is the time to wait in seconds, the second attribute is the > > function to be executed and finally "5" are "how many times the function > > will be repeated". if u don't set this last parameter the function will be > > repeated only once... > > > > hope this will help... > > > > here is the class http://www.proeye.net/omarfouad/myClasses/SetTimer.as > > > > Good luck! > > > > > > On 3/1/07, Kalani Bright <[EMAIL PROTECTED]> wrote: > > > > > > When I was using AS2 I found that no matter what there were always > > > memory > > > leaks with set interval and even after I explicitly tell Flash to remove > > > the > > > interval it never got removed... > > > > > > So even though I never wrote it I would offer the following advice, > > > which is > > > to *almost* not use setInterval at all. Just use it once, for the > > > root... > > > 1) Move all functionality for intervals to a script on the root > > > 2) The root is always available, and you won't have intervals all over > > > the > > > place > > > 3) Create only one interval for a function on the root which is > > > responsible > > > for calling functions > > > 4) The function should get the same sort of information as whats > > > required by > > > setInterval. > > > 5) Call functions based on the timer. Time since movie started. A > > > little > > > math should test if the objects which are registered with your script > > > should > > > be called again. I would also recommend enabling this function to > > > support > > > something like "call this function X times every 1000 ms). Rather than > > > call this object every 1000ms. That way you can delete it automatically > > > if > > > its reached that number. > > > 6) That script keeps information on what intervals are set > > > 7) The script periodically checks for objects which no longer exists and > > > deletes them from the interval array. > > > 8) Intervals are set or removed by calling a root function. Use the > > > delegate class to say which function gets the interval callback and also > > > > > > pass a reference to the object. > > > > > > Good luck, > > > > > > Kalani > > > > > > > > > -Original Message- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED] On Behalf Of Omar > > > Fouad > > > Sent: Wednesday, February 28, 2007 5:18 PM > > > To: Paul V.; flashcoders@chattyfig.figleaf.com > > > Subject: Re: [Flashcoders] Getting frustrated. regarding set > > > Interval,and > > > for loop. > > > > > > assign the setInterval to a variable than clear the interval this way : > > > > > > var myInterval = setInterval(blah blah blah); clearInterval(myInterval); > > > > > > read about clearInterval on the docs... U'll realize it more > > > > > > On 3/1/07, Paul V. <[EMAIL PROTECTED]> wrote: > > > > > > > > Let me explain the problem I am having and then I will send you some > > > > code. I want to load up images in a slide show with set interval, > > > > with the images being called image1 image2 image 3 etc. I want to be > > > > coding a dynamic slide show so that if I change the images I can just > > > > replace the mc images. > > > > > > > > here is the code I am working on, I am a little new to setInterval > > > > (completely new to that function actually) - I do under
RE: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
Always a pleasure having intellegent people prove me wrong. I'd rather be proved wrong by a singleton rather than a simpleton. My only comment is that setinterval doesn't fire accurately. If the user is moving the window for example the interval function will never get called. I like your manager but I still would use a timer. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks | BLITZ Sent: Wednesday, February 28, 2007 6:38 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. > So even though I never wrote it I would offer the following advice, > which is to *almost* not use setInterval at all. Hogwash. http://www.kennybunch.com/index.php?p=16 :) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
Intervals are not a problem as long as you use them correctly. Just make sure for every setInterval() call you have a corresponding clearInterval() call. Usually the clearInterval() is within your interval event handler function, so once the interval end condition is met, there's no way for your code to exit without hitting it. //PSEUDOCODE var myInterval = setInterval(myFunc, 200); myFunc(){ //do stuff if(endCondition == true){ clearInterval(myInterval); } } I've been doing things this way for a long time, and I can't even remember the last time that I had a runaway interval problem. There's no need for an IntervalManager class if you don't want to deal with that. (Nothing wrong with it, but it might be overkill.) Of course onEnterFrame is fine too if you're doing something in the context of a MovieClip, but that may not always be the case. And with that there's a danger that you need to look out for: if a MovieClip already has an onEnterFrame handler, you could overwrite it... -Adam On 2/28/07, Steven Sacks | BLITZ <[EMAIL PROTECTED]> wrote: > So even though I never wrote it I would offer the following > advice, which is to *almost* not use setInterval at all. Hogwash. http://www.kennybunch.com/index.php?p=16 :) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
As a posted last week or something, there's a few things to keep in mind when using setInterval - clear interval before setting it - always use this syntax setInterval(scope, "method", interval) - and never use this syntax setInterval(function, interval) - keep a reference to the interval - remove it when done If things go haywire, you're doing something wrong and you probably forgot one of the above. If you're referring to everything using _root, code in the main timeline and advise others to do so, please join the flashnewbie list http://chattyfig.figleaf.com/mailman/listinfo/flashnewbie regards, Muzak - Original Message - From: "Kalani Bright" <[EMAIL PROTECTED]> To: Sent: Thursday, March 01, 2007 3:15 AM Subject: RE: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. > When I was using AS2 I found that no matter what there were always memory > leaks with set interval and even after I explicitly tell Flash to remove the > interval it never got removed... > > So even though I never wrote it I would offer the following advice, which is > to *almost* not use setInterval at all. Just use it once, for the root... > 1) Move all functionality for intervals to a script on the root > 2) The root is always available, and you won't have intervals all over the > place > 3) Create only one interval for a function on the root which is responsible > for calling functions > 4) The function should get the same sort of information as whats required by > setInterval. > 5) Call functions based on the timer. Time since movie started. A little > math should test if the objects which are registered with your script should > be called again. I would also recommend enabling this function to support > something like "call this function X times every 1000 ms). Rather than > call this object every 1000ms. That way you can delete it automatically if > its reached that number. > 6) That script keeps information on what intervals are set > 7) The script periodically checks for objects which no longer exists and > deletes them from the interval array. > 8) Intervals are set or removed by calling a root function. Use the > delegate class to say which function gets the interval callback and also > pass a reference to the object. > > Good luck, > > Kalani > > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
Link Updated :D http://www.proeye.net/omarfouad/myClasses/SetTimer.rar On 3/1/07, Omar Fouad <[EMAIL PROTECTED]> wrote: well I've actually created a class called SetTimer.as that executes a function after a given time in seconds and can loop the function many times u want.. see just put the class in the same directory of the fla and use: import SetTimer; var myTimer:SetTimer = new SetTimer(2, function () {myFunction();}, 5); where "2" is the time to wait in seconds, the second attribute is the function to be executed and finally "5" are "how many times the function will be repeated". if u don't set this last parameter the function will be repeated only once... hope this will help... here is the class http://www.proeye.net/omarfouad/myClasses/SetTimer.as Good luck! On 3/1/07, Kalani Bright <[EMAIL PROTECTED]> wrote: > > When I was using AS2 I found that no matter what there were always > memory > leaks with set interval and even after I explicitly tell Flash to remove > the > interval it never got removed... > > So even though I never wrote it I would offer the following advice, > which is > to *almost* not use setInterval at all. Just use it once, for the > root... > 1) Move all functionality for intervals to a script on the root > 2) The root is always available, and you won't have intervals all over > the > place > 3) Create only one interval for a function on the root which is > responsible > for calling functions > 4) The function should get the same sort of information as whats > required by > setInterval. > 5) Call functions based on the timer. Time since movie started. A > little > math should test if the objects which are registered with your script > should > be called again. I would also recommend enabling this function to > support > something like "call this function X times every 1000 ms). Rather than > call this object every 1000ms. That way you can delete it automatically > if > its reached that number. > 6) That script keeps information on what intervals are set > 7) The script periodically checks for objects which no longer exists and > deletes them from the interval array. > 8) Intervals are set or removed by calling a root function. Use the > delegate class to say which function gets the interval callback and also > > pass a reference to the object. > > Good luck, > > Kalani > > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Omar > Fouad > Sent: Wednesday, February 28, 2007 5:18 PM > To: Paul V.; flashcoders@chattyfig.figleaf.com > Subject: Re: [Flashcoders] Getting frustrated. regarding set > Interval,and > for loop. > > assign the setInterval to a variable than clear the interval this way : > > var myInterval = setInterval(blah blah blah); clearInterval(myInterval); > > read about clearInterval on the docs... U'll realize it more > > On 3/1/07, Paul V. <[EMAIL PROTECTED]> wrote: > > > > Let me explain the problem I am having and then I will send you some > > code. I want to load up images in a slide show with set interval, > > with the images being called image1 image2 image 3 etc. I want to be > > coding a dynamic slide show so that if I change the images I can just > > replace the mc images. > > > > here is the code I am working on, I am a little new to setInterval > > (completely new to that function actually) - I do understand the basic > > syntax, setInterval( function (){ //entire function here;},1000); > > > > But I don't know how to run a for loop inside it and pass a variable > > to it. (I am a newbie). > > > > function loadImages(){//Ihave this here so I can run an > external > > for loop. > > for(i=1;i<6;i++){ > > setInterval(function(){ //set interval and begins anonymous > > function i.e function() -no name > > attachMovie("image"+i,"image"+i,41); //trying to attach the > images, > > image1 - image5 > > image = eval("image"+i);//instance assigned > to > > variable 'image' > > image._x = ((Stage.width / 2)-(image._width/2)); //positioning > > image._y = > > (yFactor);//positioning > > oldwidth = image._width; > //saving > > dimensions for resizing formula > > oldheight = > image._height;//saving > > dimensions for resizing formula > > > > image._height = yheight; //image > > height set to variable > >
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
well I've actually created a class called SetTimer.as that executes a function after a given time in seconds and can loop the function many times u want.. see just put the class in the same directory of the fla and use: import SetTimer; var myTimer:SetTimer = new SetTimer(2, function () {myFunction();}, 5); where "2" is the time to wait in seconds, the second attribute is the function to be executed and finally "5" are "how many times the function will be repeated". if u don't set this last parameter the function will be repeated only once... hope this will help... here is the class http://www.proeye.net/omarfouad/myClasses/SetTimer.as Good luck! On 3/1/07, Kalani Bright <[EMAIL PROTECTED]> wrote: When I was using AS2 I found that no matter what there were always memory leaks with set interval and even after I explicitly tell Flash to remove the interval it never got removed... So even though I never wrote it I would offer the following advice, which is to *almost* not use setInterval at all. Just use it once, for the root... 1) Move all functionality for intervals to a script on the root 2) The root is always available, and you won't have intervals all over the place 3) Create only one interval for a function on the root which is responsible for calling functions 4) The function should get the same sort of information as whats required by setInterval. 5) Call functions based on the timer. Time since movie started. A little math should test if the objects which are registered with your script should be called again. I would also recommend enabling this function to support something like "call this function X times every 1000 ms). Rather than call this object every 1000ms. That way you can delete it automatically if its reached that number. 6) That script keeps information on what intervals are set 7) The script periodically checks for objects which no longer exists and deletes them from the interval array. 8) Intervals are set or removed by calling a root function. Use the delegate class to say which function gets the interval callback and also pass a reference to the object. Good luck, Kalani -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Omar Fouad Sent: Wednesday, February 28, 2007 5:18 PM To: Paul V.; flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. assign the setInterval to a variable than clear the interval this way : var myInterval = setInterval(blah blah blah); clearInterval(myInterval); read about clearInterval on the docs... U'll realize it more On 3/1/07, Paul V. <[EMAIL PROTECTED]> wrote: > > Let me explain the problem I am having and then I will send you some > code. I want to load up images in a slide show with set interval, > with the images being called image1 image2 image 3 etc. I want to be > coding a dynamic slide show so that if I change the images I can just > replace the mc images. > > here is the code I am working on, I am a little new to setInterval > (completely new to that function actually) - I do understand the basic > syntax, setInterval( function (){ //entire function here;},1000); > > But I don't know how to run a for loop inside it and pass a variable > to it. (I am a newbie). > > function loadImages(){//Ihave this here so I can run an external > for loop. > for(i=1;i<6;i++){ > setInterval(function(){ //set interval and begins anonymous > function i.e function() -no name > attachMovie("image"+i,"image"+i,41); //trying to attach the images, > image1 - image5 > image = eval("image"+i);//instance assigned to > variable 'image' > image._x = ((Stage.width / 2)-(image._width/2)); //positioning > image._y = > (yFactor);//positioning > oldwidth = image._width; //saving > dimensions for resizing formula > oldheight = image._height;//saving > dimensions for resizing formula > > image._height = yheight; //image > height set to variable > image._width = ((oldwidth*yheight)/oldheight); //image width set to > proportions of original >},1000); > //interval to 1 sec. 1000 milliseconds > } //end > for loop > } //end > container function > > I am trying to set the images up for a second and then have them switch. > Help me out if you you know a solution. Or even if you see some > obvious errors. Like I said I am new with the set interval. by the > way if you like that little resizing technique, you can use it. Than
RE: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
> So even though I never wrote it I would offer the following > advice, which is to *almost* not use setInterval at all. Hogwash. http://www.kennybunch.com/index.php?p=16 :) ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
And another error on my part in doLoadImage replace i with movieCount Alain Rousseau wrote: Hi Paul, actually what you should do with setInterval is something like setInterval(functionReference, interval); or to keep the scope of the interval : setInterval(this, "functionReference", interval); secondly, if you want to load the image at a set interval, then your approach is wrong. You should call setInterval to attach a new movie and increment the count inside that interval. There is no delay in a for loop, at least none noticeable enough in this case. What is happening in your code is that all 5 pictures will appear at the same time after 1 second. Don't know if that's what you aim for. in the case you want the pictures to appear at a 1 second interval, your code would become : // if you're in a class do the following private var myIntrvl:Number; private var movieCount:Number; // if not : var myIntrvl:Number = 0; var movieCount:Number = 0; function loadImages() { this.clearInterval(myIntrvl); // it's best practice to clear your interval before setting it, you never know where it has been set before myIntrvl = setInterval(this, "doLoadImage", 1000); } function doLoadImage() { movieCount++; this.attachMovie("image"+i, "image"+i, 41); // allways refer to the movieClip you are attaching, in your case it's "this" image = this["image"+i]; // eval is deprecated in Flahs 8, so this is a better syntax // rest of your resizing code afterwards } Hope this helps ! Alain Paul V. wrote: Let me explain the problem I am having and then I will send you some code. I want to load up images in a slide show with set interval, with the images being called image1 image2 image 3 etc. I want to be coding a dynamic slide show so that if I change the images I can just replace the mc images. here is the code I am working on, I am a little new to setInterval (completely new to that function actually) - I do understand the basic syntax, setInterval( function (){ //entire function here;},1000); But I don't know how to run a for loop inside it and pass a variable to it. (I am a newbie). function loadImages(){//Ihave this here so I can run an external for loop. for(i=1;i<6;i++){ setInterval(function(){ //set interval and begins anonymous function i.e function() -no name attachMovie("image"+i,"image"+i,41); //trying to attach the images, image1 - image5 image = eval("image"+i);//instance assigned to variable 'image' image._x = ((Stage.width / 2)-(image._width/2)); //positioning image._y = (yFactor); //positioning oldwidth = image._width; //saving dimensions for resizing formula oldheight = image._height; //saving dimensions for resizing formula image._height = yheight; //image height set to variableimage._width = ((oldwidth*yheight)/oldheight); //image width set to proportions of original },1000); //interval to 1 sec. 1000 milliseconds } //end for loop } //end container function I am trying to set the images up for a second and then have them switch. Help me out if you you know a solution. Or even if you see some obvious errors. Like I said I am new with the set interval. by the way if you like that little resizing technique, you can use it. Thank you. Looking forward to a response on this one. Paul Vdst ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
I take that back...never use it...you can always use onEnterFrame on the root. -Original Message- From: Kalani Bright [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 28, 2007 6:15 PM To: 'flashcoders@chattyfig.figleaf.com' Subject: RE: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. When I was using AS2 I found that no matter what there were always memory leaks with set interval and even after I explicitly tell Flash to remove the interval it never got removed... So even though I never wrote it I would offer the following advice, which is to *almost* not use setInterval at all. Just use it once, for the root... 1) Move all functionality for intervals to a script on the root 2) The root is always available, and you won't have intervals all over the place 3) Create only one interval for a function on the root which is responsible for calling functions 4) The function should get the same sort of information as whats required by setInterval. 5) Call functions based on the timer. Time since movie started. A little math should test if the objects which are registered with your script should be called again. I would also recommend enabling this function to support something like "call this function X times every 1000 ms). Rather than call this object every 1000ms. That way you can delete it automatically if its reached that number. 6) That script keeps information on what intervals are set 7) The script periodically checks for objects which no longer exists and deletes them from the interval array. 8) Intervals are set or removed by calling a root function. Use the delegate class to say which function gets the interval callback and also pass a reference to the object. Good luck, Kalani -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Omar Fouad Sent: Wednesday, February 28, 2007 5:18 PM To: Paul V.; flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. assign the setInterval to a variable than clear the interval this way : var myInterval = setInterval(blah blah blah); clearInterval(myInterval); read about clearInterval on the docs... U'll realize it more On 3/1/07, Paul V. <[EMAIL PROTECTED]> wrote: > > Let me explain the problem I am having and then I will send you some > code. I want to load up images in a slide show with set interval, > with the images being called image1 image2 image 3 etc. I want to be > coding a dynamic slide show so that if I change the images I can just > replace the mc images. > > here is the code I am working on, I am a little new to setInterval > (completely new to that function actually) - I do understand the basic > syntax, setInterval( function (){ //entire function here;},1000); > > But I don't know how to run a for loop inside it and pass a variable > to it. (I am a newbie). > > function loadImages(){//Ihave this here so I can run an external > for loop. > for(i=1;i<6;i++){ > setInterval(function(){ //set interval and begins anonymous > function i.e function() -no name > attachMovie("image"+i,"image"+i,41); //trying to attach the images, > image1 - image5 > image = eval("image"+i);//instance assigned to > variable 'image' > image._x = ((Stage.width / 2)-(image._width/2)); //positioning > image._y = > (yFactor);//positioning > oldwidth = image._width; //saving > dimensions for resizing formula > oldheight = image._height;//saving > dimensions for resizing formula > > image._height = yheight; //image > height set to variable > image._width = ((oldwidth*yheight)/oldheight); //image width set to > proportions of original >},1000); > //interval to 1 sec. 1000 milliseconds > } //end > for loop > } //end > container function > > I am trying to set the images up for a second and then have them switch. > Help me out if you you know a solution. Or even if you see some > obvious errors. Like I said I am new with the set interval. by the > way if you like that little resizing technique, you can use it. Thank you. > > Looking forward to a response on this one. > > Paul Vdst > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.c
RE: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
When I was using AS2 I found that no matter what there were always memory leaks with set interval and even after I explicitly tell Flash to remove the interval it never got removed... So even though I never wrote it I would offer the following advice, which is to *almost* not use setInterval at all. Just use it once, for the root... 1) Move all functionality for intervals to a script on the root 2) The root is always available, and you won't have intervals all over the place 3) Create only one interval for a function on the root which is responsible for calling functions 4) The function should get the same sort of information as whats required by setInterval. 5) Call functions based on the timer. Time since movie started. A little math should test if the objects which are registered with your script should be called again. I would also recommend enabling this function to support something like "call this function X times every 1000 ms). Rather than call this object every 1000ms. That way you can delete it automatically if its reached that number. 6) That script keeps information on what intervals are set 7) The script periodically checks for objects which no longer exists and deletes them from the interval array. 8) Intervals are set or removed by calling a root function. Use the delegate class to say which function gets the interval callback and also pass a reference to the object. Good luck, Kalani -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Omar Fouad Sent: Wednesday, February 28, 2007 5:18 PM To: Paul V.; flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. assign the setInterval to a variable than clear the interval this way : var myInterval = setInterval(blah blah blah); clearInterval(myInterval); read about clearInterval on the docs... U'll realize it more On 3/1/07, Paul V. <[EMAIL PROTECTED]> wrote: > > Let me explain the problem I am having and then I will send you some > code. I want to load up images in a slide show with set interval, > with the images being called image1 image2 image 3 etc. I want to be > coding a dynamic slide show so that if I change the images I can just > replace the mc images. > > here is the code I am working on, I am a little new to setInterval > (completely new to that function actually) - I do understand the basic > syntax, setInterval( function (){ //entire function here;},1000); > > But I don't know how to run a for loop inside it and pass a variable > to it. (I am a newbie). > > function loadImages(){//Ihave this here so I can run an external > for loop. > for(i=1;i<6;i++){ > setInterval(function(){ //set interval and begins anonymous > function i.e function() -no name > attachMovie("image"+i,"image"+i,41); //trying to attach the images, > image1 - image5 > image = eval("image"+i);//instance assigned to > variable 'image' > image._x = ((Stage.width / 2)-(image._width/2)); //positioning > image._y = > (yFactor);//positioning > oldwidth = image._width; //saving > dimensions for resizing formula > oldheight = image._height;//saving > dimensions for resizing formula > > image._height = yheight; //image > height set to variable > image._width = ((oldwidth*yheight)/oldheight); //image width set to > proportions of original >},1000); > //interval to 1 sec. 1000 milliseconds > } //end > for loop > } //end > container function > > I am trying to set the images up for a second and then have them switch. > Help me out if you you know a solution. Or even if you see some > obvious errors. Like I said I am new with the set interval. by the > way if you like that little resizing technique, you can use it. Thank you. > > Looking forward to a response on this one. > > Paul Vdst > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com http://training.figleaf.com > -- Omar Fouad - Digital Emotions... Love is always patient and kind. It is never jealous. Love is never boastful nor conceited It is never rude or selfish. It does not take offense and is not resentful. Love takes no pleasure in other people's sins...but delights in the truth. It is alwa
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
Ahh yes forgot something to stop loading images : function doLoadImage() { movieCount++; this.attachMovie("image"+i, "image"+i, 41); // allways refer to the movieClip you are attaching, in your case it's "this" image = this["image"+i]; // eval is deprecated in Flahs 8, so this is a better syntax // rest of your resizing code afterwards // When you have all 5 images, stop calling the interval if (movieCount == 5) { this.clearInterval(myIntrvl); } } Alain Rousseau wrote: Hi Paul, actually what you should do with setInterval is something like setInterval(functionReference, interval); or to keep the scope of the interval : setInterval(this, "functionReference", interval); secondly, if you want to load the image at a set interval, then your approach is wrong. You should call setInterval to attach a new movie and increment the count inside that interval. There is no delay in a for loop, at least none noticeable enough in this case. What is happening in your code is that all 5 pictures will appear at the same time after 1 second. Don't know if that's what you aim for. in the case you want the pictures to appear at a 1 second interval, your code would become : // if you're in a class do the following private var myIntrvl:Number; private var movieCount:Number; // if not : var myIntrvl:Number = 0; var movieCount:Number = 0; function loadImages() { this.clearInterval(myIntrvl); // it's best practice to clear your interval before setting it, you never know where it has been set before myIntrvl = setInterval(this, "doLoadImage", 1000); } function doLoadImage() { movieCount++; this.attachMovie("image"+i, "image"+i, 41); // allways refer to the movieClip you are attaching, in your case it's "this" image = this["image"+i]; // eval is deprecated in Flahs 8, so this is a better syntax // rest of your resizing code afterwards } Hope this helps ! Alain Paul V. wrote: Let me explain the problem I am having and then I will send you some code. I want to load up images in a slide show with set interval, with the images being called image1 image2 image 3 etc. I want to be coding a dynamic slide show so that if I change the images I can just replace the mc images. here is the code I am working on, I am a little new to setInterval (completely new to that function actually) - I do understand the basic syntax, setInterval( function (){ //entire function here;},1000); But I don't know how to run a for loop inside it and pass a variable to it. (I am a newbie). function loadImages(){//Ihave this here so I can run an external for loop. for(i=1;i<6;i++){ setInterval(function(){ //set interval and begins anonymous function i.e function() -no name attachMovie("image"+i,"image"+i,41); //trying to attach the images, image1 - image5 image = eval("image"+i);//instance assigned to variable 'image' image._x = ((Stage.width / 2)-(image._width/2)); //positioning image._y = (yFactor); //positioning oldwidth = image._width; //saving dimensions for resizing formula oldheight = image._height; //saving dimensions for resizing formula image._height = yheight; //image height set to variableimage._width = ((oldwidth*yheight)/oldheight); //image width set to proportions of original },1000); //interval to 1 sec. 1000 milliseconds } //end for loop } //end container function I am trying to set the images up for a second and then have them switch. Help me out if you you know a solution. Or even if you see some obvious errors. Like I said I am new with the set interval. by the way if you like that little resizing technique, you can use it. Thank you. Looking forward to a response on this one. Paul Vdst ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
Hi Paul, actually what you should do with setInterval is something like setInterval(functionReference, interval); or to keep the scope of the interval : setInterval(this, "functionReference", interval); secondly, if you want to load the image at a set interval, then your approach is wrong. You should call setInterval to attach a new movie and increment the count inside that interval. There is no delay in a for loop, at least none noticeable enough in this case. What is happening in your code is that all 5 pictures will appear at the same time after 1 second. Don't know if that's what you aim for. in the case you want the pictures to appear at a 1 second interval, your code would become : // if you're in a class do the following private var myIntrvl:Number; private var movieCount:Number; // if not : var myIntrvl:Number = 0; var movieCount:Number = 0; function loadImages() { this.clearInterval(myIntrvl); // it's best practice to clear your interval before setting it, you never know where it has been set before myIntrvl = setInterval(this, "doLoadImage", 1000); } function doLoadImage() { movieCount++; this.attachMovie("image"+i, "image"+i, 41); // allways refer to the movieClip you are attaching, in your case it's "this" image = this["image"+i]; // eval is deprecated in Flahs 8, so this is a better syntax // rest of your resizing code afterwards } Hope this helps ! Alain Paul V. wrote: Let me explain the problem I am having and then I will send you some code. I want to load up images in a slide show with set interval, with the images being called image1 image2 image 3 etc. I want to be coding a dynamic slide show so that if I change the images I can just replace the mc images. here is the code I am working on, I am a little new to setInterval (completely new to that function actually) - I do understand the basic syntax, setInterval( function (){ //entire function here;},1000); But I don't know how to run a for loop inside it and pass a variable to it. (I am a newbie). function loadImages(){//Ihave this here so I can run an external for loop. for(i=1;i<6;i++){ setInterval(function(){ //set interval and begins anonymous function i.e function() -no name attachMovie("image"+i,"image"+i,41); //trying to attach the images, image1 - image5 image = eval("image"+i);//instance assigned to variable 'image' image._x = ((Stage.width / 2)-(image._width/2)); //positioning image._y = (yFactor);//positioning oldwidth = image._width; //saving dimensions for resizing formula oldheight = image._height;//saving dimensions for resizing formula image._height = yheight; //image height set to variable image._width = ((oldwidth*yheight)/oldheight); //image width set to proportions of original },1000); //interval to 1 sec. 1000 milliseconds }//end for loop } //end container function I am trying to set the images up for a second and then have them switch. Help me out if you you know a solution. Or even if you see some obvious errors. Like I said I am new with the set interval. by the way if you like that little resizing technique, you can use it. Thank you. Looking forward to a response on this one. Paul Vdst ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
assign the setInterval to a variable than clear the interval this way : var myInterval = setInterval(blah blah blah); clearInterval(myInterval); read about clearInterval on the docs... U'll realize it more On 3/1/07, Paul V. <[EMAIL PROTECTED]> wrote: Let me explain the problem I am having and then I will send you some code. I want to load up images in a slide show with set interval, with the images being called image1 image2 image 3 etc. I want to be coding a dynamic slide show so that if I change the images I can just replace the mc images. here is the code I am working on, I am a little new to setInterval (completely new to that function actually) - I do understand the basic syntax, setInterval( function (){ //entire function here;},1000); But I don't know how to run a for loop inside it and pass a variable to it. (I am a newbie). function loadImages(){//Ihave this here so I can run an external for loop. for(i=1;i<6;i++){ setInterval(function(){ //set interval and begins anonymous function i.e function() -no name attachMovie("image"+i,"image"+i,41); //trying to attach the images, image1 - image5 image = eval("image"+i);//instance assigned to variable 'image' image._x = ((Stage.width / 2)-(image._width/2)); //positioning image._y = (yFactor);//positioning oldwidth = image._width; //saving dimensions for resizing formula oldheight = image._height;//saving dimensions for resizing formula image._height = yheight; //image height set to variable image._width = ((oldwidth*yheight)/oldheight); //image width set to proportions of original },1000); //interval to 1 sec. 1000 milliseconds }//end for loop } //end container function I am trying to set the images up for a second and then have them switch. Help me out if you you know a solution. Or even if you see some obvious errors. Like I said I am new with the set interval. by the way if you like that little resizing technique, you can use it. Thank you. Looking forward to a response on this one. Paul Vdst ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- Omar Fouad - Digital Emotions... Love is always patient and kind. It is never jealous. Love is never boastful nor conceited It is never rude or selfish. It does not take offense and is not resentful. Love takes no pleasure in other people's sins...but delights in the truth. It is always ready to excuse, to trust, to hope... and to endure... whatever comes. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Getting frustrated. regarding set Interval, and for loop.
Paul: I understand what you're trying to do (make a time-delay slide show of images). Using setInterval for that is fine, but you have to make sure you're using it correctly. Calling setInterval will set up a flash system timer that will call your function every X milliseconds. It will keep going, and keep calling that function (every X milliseconds), until it's stopped. Hence, there is no reason for you to be calling setInterval in a loop and setting up 5 timers (that will each repeat forever). Simply have 1 timer, that repeats 5 times, then you stop it. To do this in simplified code: //set up the call count. _root.timerCalls = 0; //make the function that will be called. function foo() { trace("Timer function got called!"); if(_root.timerCalls++ == 4) { trace("Max calls reached. Stopping timer..."); clearInterval(_root.myTimerID); //timer will never get called again. _root.timerCalls = 0; //reset counter } //do "stuff" (every 1sec). } //make the timer, and start it. _root.myTimerID = setInterval(foo, 1000); //system will call foo() every second until you stop it. Timer ID gets stored into _root.myTimerID. This is just one way to do it. In your timer function, you'll implement your code for loading the new image, and taking away the old one. -=matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul V. Sent: Wednesday, February 28, 2007 5:03 PM To: Flashnewbie Mailing List; Flashcoders mailing list Subject: [Flashcoders] Getting frustrated. regarding set Interval,and for loop. Let me explain the problem I am having and then I will send you some code. I want to load up images in a slide show with set interval, with the images being called image1 image2 image 3 etc. I want to be coding a dynamic slide show so that if I change the images I can just replace the mc images. here is the code I am working on, I am a little new to setInterval (completely new to that function actually) - I do understand the basic syntax, setInterval( function (){ //entire function here;},1000); But I don't know how to run a for loop inside it and pass a variable to it. (I am a newbie). function loadImages(){//Ihave this here so I can run an external for loop. for(i=1;i<6;i++){ setInterval(function(){ //set interval and begins anonymous function i.e function() -no name attachMovie("image"+i,"image"+i,41); //trying to attach the images, image1 - image5 image = eval("image"+i);//instance assigned to variable 'image' image._x = ((Stage.width / 2)-(image._width/2)); //positioning image._y = (yFactor); //positioning oldwidth = image._width; //saving dimensions for resizing formula oldheight = image._height;//saving dimensions for resizing formula image._height = yheight; //image height set to variable image._width = ((oldwidth*yheight)/oldheight); //image width set to proportions of original },1000); //interval to 1 sec. 1000 milliseconds } //end for loop } //end container function I am trying to set the images up for a second and then have them switch. Help me out if you you know a solution. Or even if you see some obvious errors. Like I said I am new with the set interval. by the way if you like that little resizing technique, you can use it. Thank you. Looking forward to a response on this one. Paul Vdst ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com