Re: [flexcoders] Re: help with setInterval...
Indeed, I stand corrected. Many thanks Abdul. Dave On 4/23/05, Abdul Qabiz [EMAIL PROTECTED] wrote: Hi, However, I'm still unable to do the following: Call a setInterval within a class. Have the setInterval pass over a number. And the function called increment that number. Pass this new number to a textfield object. If I call: setInterval(this,somefunction, 1000, 5) function somefunction ( e : Number) { e++ mx.controls.Alert.show(e) // shows 6 } I think, it would trace 6 repeatedly over the interval. And I feel that there is no reason it won't work. I just created a sample to verify if my feelings are right :) This sample is demonstrating setInterval(..) inside a class. Look at the attached files or code later in this mail. Hope that helps... -abdul 1) ##Counter.as## import mx.core.UIObject; [Event(start)] [Event(increment)] [Event(stop)] class Counter extends UIObject { var counterIntervalId:Number; var __delay:Number = 50; var __min:Number = 0; var __max:Number = 100; var __count:Number = 0; var running:Boolean = false; function Counter(delay:Number, min:Number, max:Number) { __min = min ? min : 0; __max = max ? max : 100; __delay = delay ? delay : 50; } function startCounter():Void { __count = 0; running = true; dispatchEvent({type:start}); counterIntervalId = setInterval(this,incrementCount, __delay, __min); //you can also do this: //counterIntervalId = setInterval(mx.utils.Delegate.create(this,incrementCount), __delay, __min); } function incrementCount(num):Void { if(__count __max) { //un-comment the following to see setInterval(..) passes same number agian and again // mx.controls.Alert.show(num.toString()); __count++; dispatchEvent({type:increment}); } else { stopCounter(); } } function stopCounter():Void { clearInterval(counterIntervalId); __count = 0; running = false dispatchEvent({type:stop}); } function get min():Number { return __min; } function set min(newValue:Number):Void { __min = newValue; } function get max():Number { return __max; } function set max(newValue:Number):Void { __max = newValue; } function get value():Number { return __count; } } 2) ##setIntervalExample.mxml## ?xml version=1.0 encoding=iso-8859-1? mx:Application width=800 height=600 xmlns:mx=http://www.macromedia.com/2003/mxml; initialize=onAppInit() mx:Script ![CDATA[ import Counter; import mx.utils.Delegate; var counter:Counter; function onAppInit() { counter = new Counter(); changeLimit(); counter.addEventListener(start, Delegate.create(this, onCounterStart)); counter.addEventListener(increment, Delegate.create(this, onCounterIncrement)); counter.addEventListener(stop, Delegate.create(this, onCounterStop)); } function onCounterStart(event) { _ta.text +=Counter started..\n; } function onCounterIncrement(event) { _ta.text += event.target.value + \n; } function onCounterStop(event) { _ta.text += Counter stopped...\n; } function changeLimit() { counter.min = slider.values[0]; counter.max = slider.values[1]; } ]] /mx:Script mx:HBox mx:Label text=Count:/mx:TextArea id=_ta width=300 height=150 / /mx:HBox mx:HBox mx:Button label=Start Counter click=counter.startCounter(); enabled={!counter.running}/ mx:Button label=Stop Counter click=counter.stopCounter(); enabled={counter.running}/ /mx:HBox mx:HSlider id=slider toolTipPlacement=top thumbCount=2 labels=['min', 'max'] values=[0, 100] snapInterval=1 change=changeLimit(); allowTrackClick=true maximum=1000 minimum=0/ /mx:Application -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] Sent: Saturday, April 23, 2005 7:22 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: help with setInterval... Hi Abdul, I ran into a similar issue. In short, whether my code was not scoped in an MXML file or whether it was within a class, I could not pass
Re: [flexcoders] Re: help with setInterval...
heh, yeah i misplaced a paren on purpose to see who was paying attention. ;) and if you believe that /mgk Abdul Qabiz wrote: Hi terry_hrtn, Can you post the entire code now? I would like to see why it's not working. Correcting Michael's suggestion: setInterval(mx.utils.Delegate.create(this, upCount), 1000); I just tested your code after resolving scope issues, it works fine for me -abdul -Original Message- From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] Sent: Saturday, April 23, 2005 12:31 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: help with setInterval... Does not work. On 4/12/05, michael keirnan [EMAIL PROTECTED] wrote: it would be good to go through the Flex UG sections on scoping and event listeners. in the long run understanding scope is invaluable. in your test case the following might work: setInterval(mx.utils.Delegate.create(this, upCount, 1000); /mgk terry_hrtn wrote: Matt...now I'm getting the message below in the debug file...any suggestions. Warning: [type Function] is not a function at () --- In flexcoders@yahoogroups.com, Matt Chotin [EMAIL PROTECTED] wrote: You're having scope issues. setInterval(this, "upCount", 1000); More info here: http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm Matt _ From: terry_hrtn [mailto:[EMAIL PROTECTED]...] Sent: Monday, April 11, 2005 10:03 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] help with setInterval... Needing some help with setInterval... Can someone tell me why "setInterval" calls the "upCount" function but does not update label on screen? ?xml version="1.0" encoding="utf-8"? mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml http://www.macromedia.com/2003/mxml " mx:Script ![CDATA[ var nCnt : Number = 0; var lClock : Number = -1; function startClock() { btStart.enabled = false; btStop.enabled = true; upCount(); lClock = setInterval(upCount,1000); lbClockStat.text = 'Started! (' + lClock + ')'; } function upCount() { nCnt += 1; lbShow.text = 'Count: ' + nCnt; } function stopClock() { lbClockStat.text = "Stopped at " + nCnt; nCnt = 0; btStop.enabled = false; btStart.enabled = true; clearInterval(lClock); } ]] /mx:Script mx:Panel width="304" height="121" mx:Label id="lbShow" text="start" / mx:HBox mx:Button id="btStart" label="Start Clock" click="startClock()" / mx:Button id="btStop" label="Stop Clock" click="stopClock()" enabled="false" / /mx:HBox mx:Label id="lbClockStat" / /mx:Panel /mx:Application _ Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to the Yahoo! http://docs.yahoo.com/info/terms/ Terms of Service. Yahoo! Groups Links Yahoo! Groups Links Yahoo! Groups Links Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ Yahoo! Groups Links To visit your group on the web, go to:http://groups.yahoo.com/group/flexcoders/ To unsubscribe from this group, send an email to:[EMAIL PROTECTED] Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
RE: [flexcoders] Re: help with setInterval...
Hi terry_hrtn, Can you post the entire code now? I would like to see why it's not working. Correcting Michael's suggestion: setInterval(mx.utils.Delegate.create(this, upCount), 1000); I just tested your code after resolving scope issues, it works fine for me -abdul -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] Sent: Saturday, April 23, 2005 12:31 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: help with setInterval... Does not work. On 4/12/05, michael keirnan [EMAIL PROTECTED] wrote: it would be good to go through the Flex UG sections on scoping and event listeners. in the long run understanding scope is invaluable. in your test case the following might work: setInterval(mx.utils.Delegate.create(this, upCount, 1000); /mgk terry_hrtn wrote: Matt...now I'm getting the message below in the debug file...any suggestions. Warning: [type Function] is not a function at () --- In flexcoders@yahoogroups.com, Matt Chotin [EMAIL PROTECTED] wrote: You're having scope issues. setInterval(this, upCount, 1000); More info here: http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm Matt _ From: terry_hrtn [mailto:[EMAIL PROTECTED] Sent: Monday, April 11, 2005 10:03 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] help with setInterval... Needing some help with setInterval... Can someone tell me why setInterval calls the upCount function but does not update label on screen? ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.macromedia.com/2003/mxml http://www.macromedia.com/2003/mxml mx:Script ![CDATA[ var nCnt : Number = 0; var lClock : Number = -1; function startClock() { btStart.enabled = false; btStop.enabled = true; upCount(); lClock = setInterval(upCount,1000); lbClockStat.text = 'Started! (' + lClock + ')'; } function upCount() { nCnt += 1; lbShow.text = 'Count: ' + nCnt; } function stopClock() { lbClockStat.text = Stopped at + nCnt; nCnt = 0; btStop.enabled = false; btStart.enabled = true; clearInterval(lClock); } ]] /mx:Script mx:Panel width=304 height=121 mx:Label id=lbShow text=start / mx:HBox mx:Button id=btStart label=Start Clock click=startClock() / mx:Button id=btStop label=Stop Clock click=stopClock() enabled=false / /mx:HBox mx:Label id=lbClockStat / /mx:Panel /mx:Application _ Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to the Yahoo! http://docs.yahoo.com/info/terms/ Terms of Service. Yahoo! Groups Links Yahoo! Groups Links Yahoo! Groups Links Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Re: [flexcoders] Re: help with setInterval...
Hi Abdul, I ran into a similar issue. In short, whether my code was not scoped in an MXML file or whether it was within a class, I could not pass over a parameter (a number in my case) and have the function called by the setInterval reference the parameter passed over more than 1x. With Terry's problem, I had experienced something similar using Cairngorm with Flex. I could not get my textfield (or label) to update if I called a function that called a setInterval. If I called the function directly it worked. I fixed this when I stuck the code in a class and specified the object with view.MyTextfield.text. However, I'm still unable to do the following: Call a setInterval within a class. Have the setInterval pass over a number. And the function called increment that number. Pass this new number to a textfield object. If I call: setInterval(this,somefunction, 1000, 5) function somefunction ( e : Number) { e++ mx.controls.Alert.show(e) // shows 6 } My code is at work, but the above is what I remember as having not worked. It works if I set a default value within the function. But as a parameter, the value fails. Best, Dave Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Re: [flexcoders] Re: help with setInterval...
Does not work. On 4/12/05, michael keirnan [EMAIL PROTECTED] wrote: it would be good to go through the Flex UG sections on scoping and event listeners. in the long run understanding scope is invaluable. in your test case the following might work: setInterval(mx.utils.Delegate.create(this, upCount, 1000); /mgk terry_hrtn wrote: Matt...now I'm getting the message below in the debug file...any suggestions. Warning: [type Function] is not a function at () --- In flexcoders@yahoogroups.com, Matt Chotin [EMAIL PROTECTED] wrote: You're having scope issues. setInterval(this, upCount, 1000); More info here: http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm Matt _ From: terry_hrtn [mailto:[EMAIL PROTECTED] Sent: Monday, April 11, 2005 10:03 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] help with setInterval... Needing some help with setInterval... Can someone tell me why setInterval calls the upCount function but does not update label on screen? ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.macromedia.com/2003/mxml http://www.macromedia.com/2003/mxml mx:Script ![CDATA[ var nCnt : Number = 0; var lClock : Number = -1; function startClock() { btStart.enabled = false; btStop.enabled = true; upCount(); lClock = setInterval(upCount,1000); lbClockStat.text = 'Started! (' + lClock + ')'; } function upCount() { nCnt += 1; lbShow.text = 'Count: ' + nCnt; } function stopClock() { lbClockStat.text = Stopped at + nCnt; nCnt = 0; btStop.enabled = false; btStart.enabled = true; clearInterval(lClock); } ]] /mx:Script mx:Panel width=304 height=121 mx:Label id=lbShow text=start / mx:HBox mx:Button id=btStart label=Start Clock click=startClock() / mx:Button id=btStop label=Stop Clock click=stopClock() enabled=false / /mx:HBox mx:Label id=lbClockStat / /mx:Panel /mx:Application _ Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to the Yahoo! http://docs.yahoo.com/info/terms/ Terms of Service. Yahoo! Groups Links Yahoo! Groups Links Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
RE: [flexcoders] Re: help with setInterval...
Hi, However, I'm still unable to do the following: Call a setInterval within a class. Have the setInterval pass over a number. And the function called increment that number. Pass this new number to a textfield object. If I call: setInterval(this,somefunction, 1000, 5) function somefunction ( e : Number) { e++ mx.controls.Alert.show(e) // shows 6 } I think, it would trace 6 repeatedly over the interval. And I feel that there is no reason it won't work. I just created a sample to verify if my feelings are right :) This sample is demonstrating setInterval(..) inside a class. Look at the attached files or code later in this mail. Hope that helps... -abdul 1) ##Counter.as## import mx.core.UIObject; [Event(start)] [Event(increment)] [Event(stop)] class Counter extends UIObject { var counterIntervalId:Number; var __delay:Number = 50; var __min:Number = 0; var __max:Number = 100; var __count:Number = 0; var running:Boolean = false; function Counter(delay:Number, min:Number, max:Number) { __min = min ? min : 0; __max = max ? max : 100; __delay = delay ? delay : 50; } function startCounter():Void { __count = 0; running = true; dispatchEvent({type:start}); counterIntervalId = setInterval(this,incrementCount, __delay, __min); //you can also do this: //counterIntervalId = setInterval(mx.utils.Delegate.create(this,incrementCount), __delay, __min); } function incrementCount(num):Void { if(__count __max) { //un-comment the following to see setInterval(..) passes same number agian and again // mx.controls.Alert.show(num.toString()); __count++; dispatchEvent({type:increment}); } else { stopCounter(); } } function stopCounter():Void { clearInterval(counterIntervalId); __count = 0; running = false dispatchEvent({type:stop}); } function get min():Number { return __min; } function set min(newValue:Number):Void { __min = newValue; } function get max():Number { return __max; } function set max(newValue:Number):Void { __max = newValue; } function get value():Number { return __count; } } 2) ##setIntervalExample.mxml## ?xml version=1.0 encoding=iso-8859-1? mx:Application width=800 height=600 xmlns:mx=http://www.macromedia.com/2003/mxml; initialize=onAppInit() mx:Script ![CDATA[ import Counter; import mx.utils.Delegate; var counter:Counter; function onAppInit() { counter = new Counter(); changeLimit(); counter.addEventListener(start, Delegate.create(this, onCounterStart)); counter.addEventListener(increment, Delegate.create(this, onCounterIncrement)); counter.addEventListener(stop, Delegate.create(this, onCounterStop)); } function onCounterStart(event) { _ta.text +=Counter started..\n; } function onCounterIncrement(event) { _ta.text += event.target.value + \n; } function onCounterStop(event) { _ta.text += Counter stopped...\n; } function changeLimit() { counter.min = slider.values[0]; counter.max = slider.values[1]; } ]] /mx:Script mx:HBox mx:Label text=Count:/mx:TextArea id=_ta width=300 height=150 / /mx:HBox mx:HBox mx:Button label=Start Counter click=counter.startCounter(); enabled={!counter.running}/ mx:Button label=Stop Counter click=counter.stopCounter(); enabled={counter.running}/ /mx:HBox mx:HSlider id=slider toolTipPlacement=top thumbCount=2 labels=['min', 'max'] values=[0, 100] snapInterval=1 change=changeLimit(); allowTrackClick=true maximum=1000 minimum=0/ /mx:Application -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] Sent: Saturday, April 23, 2005 7:22 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: help with setInterval... Hi Abdul, I ran into a similar issue. In short, whether my code was not scoped in an MXML file or whether it was within a class, I could not pass over a parameter (a number in my case) and have the function
Re: [flexcoders] Re: help with setInterval...
it would be good to go through the Flex UG sections on scoping and event listeners. in the long run understanding scope is invaluable. in your test case the following might work: setInterval(mx.utils.Delegate.create(this, upCount, 1000); /mgk terry_hrtn wrote: Matt...now I'm getting the message below in the debug file...any suggestions. Warning: [type Function] is not a function at () --- In flexcoders@yahoogroups.com, Matt Chotin [EMAIL PROTECTED] wrote: You're having scope issues. setInterval(this, upCount, 1000); More info here: http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm Matt _ From: terry_hrtn [mailto:[EMAIL PROTECTED] Sent: Monday, April 11, 2005 10:03 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] help with setInterval... Needing some help with setInterval... Can someone tell me why setInterval calls the upCount function but does not update label on screen? ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.macromedia.com/2003/mxml http://www.macromedia.com/2003/mxml mx:Script ![CDATA[ var nCnt : Number = 0; var lClock : Number = -1; function startClock() { btStart.enabled = false; btStop.enabled = true; upCount(); lClock = setInterval(upCount,1000); lbClockStat.text = 'Started! (' + lClock + ')'; } function upCount() { nCnt += 1; lbShow.text = 'Count: ' + nCnt; } function stopClock() { lbClockStat.text = Stopped at + nCnt; nCnt = 0; btStop.enabled = false; btStart.enabled = true; clearInterval(lClock); } ]] /mx:Script mx:Panel width=304 height=121 mx:Label id=lbShow text=start / mx:HBox mx:Button id=btStart label=Start Clock click=startClock() / mx:Button id=btStop label=Stop Clock click=stopClock() enabled=false / /mx:HBox mx:Label id=lbClockStat / /mx:Panel /mx:Application _ Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to the Yahoo! http://docs.yahoo.com/info/terms/ Terms of Service. Yahoo! Groups Links Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
[flexcoders] Re: help with setInterval...
Matt...now I'm getting the message below in the debug file...any suggestions. Warning: [type Function] is not a function at () --- In flexcoders@yahoogroups.com, Matt Chotin [EMAIL PROTECTED] wrote: You're having scope issues. setInterval(this, upCount, 1000); More info here: http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm http://livedocs.macromedia.com/flex/15/flex_docs_en/1662.htm Matt _ From: terry_hrtn [mailto:[EMAIL PROTECTED] Sent: Monday, April 11, 2005 10:03 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] help with setInterval... Needing some help with setInterval... Can someone tell me why setInterval calls the upCount function but does not update label on screen? ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.macromedia.com/2003/mxml http://www.macromedia.com/2003/mxml mx:Script ![CDATA[ var nCnt : Number = 0; var lClock : Number = -1; function startClock() { btStart.enabled = false; btStop.enabled = true; upCount(); lClock = setInterval(upCount,1000); lbClockStat.text = 'Started! (' + lClock + ')'; } function upCount() { nCnt += 1; lbShow.text = 'Count: ' + nCnt; } function stopClock() { lbClockStat.text = Stopped at + nCnt; nCnt = 0; btStop.enabled = false; btStart.enabled = true; clearInterval(lClock); } ]] /mx:Script mx:Panel width=304 height=121 mx:Label id=lbShow text=start / mx:HBox mx:Button id=btStart label=Start Clock click=startClock() / mx:Button id=btStop label=Stop Clock click=stopClock() enabled=false / /mx:HBox mx:Label id=lbClockStat / /mx:Panel /mx:Application _ Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to the Yahoo! http://docs.yahoo.com/info/terms/ Terms of Service. Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/