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
> 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
> 
> 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/
 



Reply via email to